C program to sort array elements in descending order

 

C program to sort array elements in  descending order

/********************************************

 C program to sort array elements in  descending order

 *******************************************/

#include<stdio.h>

#include<conio.h>

void main()

{

int arr[100];

int n,i,j,temp;

clrscr();

printf("How many array elements\n");

scanf("%d",&n);

printf("Enter array elements\n");

for(i=0;i<n;i++)

{

scanf("%d",&arr[i]);

}

printf("The sorting order of array elements is\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("%d\t",arr[i]);

}

printf("\nEnd of program");

}


How many array elements

10

Enter array elements

1 2 3 4 5 6 7 8 9 10

The sorting order of array elements is

10 9 8 7 6 5 4 3 2 1

End of program


टिप्पणी पोस्ट करा

0 टिप्पण्या