Sorting of Array Descending C programs

This program sorts an array in descending order using functions. This is a part of Mumbai University MCA Colleges C Programming MCA Sem 1



#include<conio.h>
#include<stdio.h>
void main()
{
int ar[50],sz,i;
void srt(int a[50],int);
clrscr();
printf("\n Enter size of array: ");
scanf("%d",&sz);
printf("\n Enter %d elements: ",sz);
for(i=0;i<sz;i++)
{
scanf("%d",&ar[i]);
}
srt(ar,sz);
getch();
}
void srt(int ar[],int sz)
{
int l,m;
for(l=0;l<sz;l++)
for(m=0;m<sz-1;m++)
{
if(ar[m]<ar[m+1])
{
ar[m]=ar[m]+ar[m+1];
ar[m+1]=ar[m]-ar[m+1];
ar[m]=ar[m]-ar[m+1];
}
}
printf("\n Descending order: ");
for(l=0;l<sz;l++)
{
printf("\n %d ",ar[l]);
}
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment