/* write a c program to accept n number from the user & store these
number into an array and sort the array element */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,no[20];
int i,j,temp=0;
clrscr();
printf("how many number you want to enter :\n");
scanf("%d",&n);
printf("enter the number :");
for(i=0;i<n;i++)
{
scanf("%d",&no[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(no[i]>no[j])
{
temp=no[i];
no[i]=no[j];
no[j]=temp;
}
}
}
printf("the sorted array :\n");
for(i=0;i<n;i++)
{
printf("\n%d",no[i]);
}
getch();
}
/*how many number you want to enter :
3
enter the number :12
78
8
the sorted array :
8
12
78
*/
No comments:
Post a Comment