Friday, April 10, 2015

17. Write a C program to sort integer values in descending order.

#include<stdio.h>#include<conio.h>
void main()
{
int num[100],i,j,n,temp;
clrscr();
printf("\n How many data:- ");
scanf("%d",&n);
printf("\n Input %d data's:-",n);
for(i=0;i<n;i++)
{
printf("\n num[%d]:- ",i);
scanf("%d", &num[i]);
}
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("\n The data in descending orders are:\n");
for(i=0;i<n;i++)
 {
printf("%5d",num[i]);
}
getch();
}

No comments:

Post a Comment