Write a C program to sort the 10 Given numbers in Ascending order

#include<stdio.h>
int main ()
{
int a[5];
int i,j,temp;
for(i=0;i<5;i++)
{
printf("Enter value for a[%d]",i);
scanf("%d",&a[i]);
}
for(i=0;i<4;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("Ascending order =\n");
for(i=0;i<5;i++)
printf("\t %d",a[i]);
return 0;
}

Post a Comment

0 Comments