Here is the program to set the array elements in the ascending order
Code:#include <stdio.h> int main() { int Arr[100],n,i,step,temp; printf("Enter the number of array elements\n"); scanf("%d",&n); for(i=0;i<n;++i){ printf("Enter Arr%d:\n",i+1); scanf("%d",&Arr[i]); } for(step=0;step<n-1;++step) for(i=0;i<n-step;++i) { if(Arr[i]>Arr[i+1]) { temp=Arr[i]; Arr[i]=Arr[i+1]; Arr[i+1]=temp; } } printf("In ascending order:\n"); for(i=0;i<n;++i) printf("%d\t",Arr[i]); return 0; }
Bookmarks