C Program To Sort Array in Ascending Order
Learn How To Sort Array in Ascending Order in C Programming. It is important that we should know How A For Loop Works before getting further with the C Program Code. This Array Sorting C Program is basically done on a 1 – Dimensional Array. The Code For Sorting Arrays with Ascending Order method is executed using For Loops.
Also Read: C Program To Find Roots of Quadratic Equations
C Program To Sort Array in Ascending Order using For Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include<stdio.h> int main() { int arr[50], temp; int limit, i, j; printf("\nEnter the size of the array: \t"); scanf("%d", &limit); for(i = 0; i < limit; i++) { printf("Enter Element %d:\t", i + 1); scanf("%d", &arr[i]); } printf("\nArray\n"); for(i = 0; i < limit; i++) { printf("%d\t", arr[i]); } for(i = 0; i < limit; i++) { for(j = 0; j < limit; j++) { if(arr[i] < arr[j]) { temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } } printf("\nSorted Array\n"); for(i = 0; i < limit; i++) { printf("%d\t", arr[i]); } printf("\n"); return 0; } |
Also Read: Find Sum of Lower Triangular Elements in C Programming
Output

If you have any compilation errors or doubts in this C Program To Sort Array Elements in Ascending Order, let us know about it in the Comment Section below.