SORTING
#include<conio.h>
int main()
{
int i,j,a,n,number[30];
printf("enter the value of N \n");
scanf("%d",&n);
printf("enter the number \n");
for(i=0;i<n;++i)
scanf("%d",&number[i]);
for(i=0;i<n;++i)
{
for(j=i+1;j<n;++j)
{
if(number[i]>number[j])
{
a=number[i];
number[i]=number[j];
number[j]=a;
}
}
}
printf("the number arranged in ascending order is given below \n");
for(i=0;i<n;++i)
printf("%d\n",number[i]);
getch();
}
OUTPUT
enter the value of N
5
enter the number
54
90
33
22
31
the number arranged in ascending order is given below
22
31
33
54
90
No comments:
Post a Comment
Note: only a member of this blog may post a comment.