Program in C to enter ten integer numbers in array, sort and display them in ascending order.

C Language and Arrays

C language is a building block for many other currently known languages. C language has variety of data types and powerful operators. Due to this, programs written in C language are efficient, fast and easy to understand.


Arrays in C

Array in C are user defined variables that are used to store multiple values in a single variable.

Since, we have to enter ten numbers of same data type, we can use array to store them and with the help of for loop, we can store, sort and display them.


Example Program: Store, Sort, and Display Array

#include<stdio.h> int main() { int arr[10],i,j,temp; printf("Enter any ten integer numbers\n"); // Input numbers into the array for(i=0;i<10;i++) { scanf("%d",&arr[i]); } // Sorting array in ascending order for(i=0;i<9;i++) { for(j=i+1;j<10;j++) { if(arr[i]>arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } // Display the sorted array printf("The numbers in ascending order are:\n"); for(i=0;i<10;i++) printf("%d\t", arr[i]); return 0; }

Sample Output

Enter any ten integer numbers: 1 3 2 1 4 6 4 8 9 3 The numbers in ascending order are: 1 1 2 3 3 4 4 6 8 9

Conclusion

Using arrays in C simplifies the process of storing, sorting, and displaying multiple values of the same type. With loops and array structures, programs become more organized and efficient. This example demonstrates how C can handle user input, perform sorting, and provide output in a clear and structured way, highlighting the language's power and versatility in handling data.

array, sort and display them in ascending order.

You can type C code and run the program from this link 

C Compiler



Previous Post Next Post