//program to sort 'n' elements in descending order
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int arr[200];
int size;
int i,j,k;
printf("now,enter size of elements \n");
scanf("%d",&size);
printf("enter array's elements\n");
for(i=0;i<size;i++)
{
printf("enter elements for location=%d\n",i);
scanf("%d",&arr[i]);
}
printf("elements' sorting process started\n");
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(arr[i]<arr[j])
{
k=arr[i];
arr[i]=arr[j];
arr[j]=k;
}
}
}
printf("in descending order,elements are\n");
for(i=0;i<size;i++)
{
printf("%d\n",arr[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int arr[200];
int size;
int i,j,k;
printf("now,enter size of elements \n");
scanf("%d",&size);
printf("enter array's elements\n");
for(i=0;i<size;i++)
{
printf("enter elements for location=%d\n",i);
scanf("%d",&arr[i]);
}
printf("elements' sorting process started\n");
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(arr[i]<arr[j])
{
k=arr[i];
arr[i]=arr[j];
arr[j]=k;
}
}
}
printf("in descending order,elements are\n");
for(i=0;i<size;i++)
{
printf("%d\n",arr[i]);
}
getch();
}
No comments:
Post a Comment