Display Numbers in Ascending Order C language
Develop a program in C Language to accept five numbers as input and then Display Numbers in Ascending Order .
#include<stdio.h> #include<conio.h> void main() { int n,i,j,num[20],temp; clrscr(); printf(“\nEnter how many numbers to be sorted:\n”); scanf(“%d”,&n); printf(“\nEnter the %d numbers :”,n); for(i=0;i<n;i++) { scanf(“%d”,&num[i]); } //the following code is for sorting for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(num[i]>num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } printf(“\nElements in sorted order are : \n”); for(i=0;i<n;i++) { printf(“%d\t”,num[i]); } getch(); }
Leave a Reply