Jan 30, 2014

C program for sorting the elements of an array in descending order.


#include<stdio.h>
#include<conio.h>

void main()
{
int *arr, temp, i, j, n;
clrscr();
printf(“enter the number of elements in the array”);
scanf(“%d”, &n);
arr=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
{
for(j=i+1; j<n; j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
printf(“Elements of array in descending order are”);
for(i=0; i<n; i++);
getch();
}

0 comments:

Post a Comment