Write a program to sort the array elements in ascending order
#include<stdio.h> void read(int[],int); void asc(int[],int); int main() { int a[20],i,n; printf("Enter the size of an array.\n"); scanf("%d",&n); read(a,n); asc(a,n); printf("In ascending order:\n"); for(i=0;i<n;i++) printf("%d\n",a[i]); return 0; } void read(int b[20],int q) { int i; printf("Enter the element:\n"); for(i=0;i<q;i++) scanf("%d",&b[i]); } void asc(int c[20],int r) { int i,j,temp; for(i=0;i<r-1;i++){ for(j=i+1;j<r;j++){ if(c[i]>c[j]){ temp=c[i]; c[i]=c[j]; c[j]=temp; } } } }
Output
Enter the size of an array.
5
Enter the element:
2
3
6
4
8
In ascending order:
2
3
4
6
8