Tuesday, 19 August 2014

Accept 10 numbers and store in an array, print sorted array in descending and ascending order


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,temp;
clrscr();
printf("Enter 10 nos\n");

for(i=0;i<10 i="" nbsp="" span="">
 scanf("%d",&a[i]);
 for(i=0;i<10 i="" span="">
 { 
 for(j=i+1;j<10 j="" span="">
 {
 if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<10 i="" span="">
 printf(" %d ",a[i]);
 printf(" Nos sorted in ascending order\n");
 printf("\n");
 for(i=9;i>=0;i--)
printf(" %d ",a[i]);
printf(" Nos sorted in descending order\n");
getch();
}

No comments:

Post a Comment