C program to sort an array in descending order.
In this tutorial we will solve a problem to sort the array in descending order.
Here we will write a c program source code to sort the array elements in descending order.
This program will accept the range or size of an array that entered by user through the keyboard.
After it we will enter the elements of this array.
After these steps compiler check and execute the conditions and print a new list of array elements after sorting in descending order.
C PROGRAM CODE
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,num,temp;
int array[100];
clrscr();
printf("\n ENTER NUMBER OF ELEMENTS:\n ");
scanf("%d",&num);
printf("\n ENTER THE NUMBERS:\n ");
for(a=0;a<num;a++)
{
scanf("%d",&array[a]);
}
for(a=0;a<num;a++)
{
for(b=a+1;b<num;b++)
{
if(array[a]<array[b])
{
temp=array[a];
array[a]=array[b];
array[b]=temp;
}
}
}
printf("\n DESCENDING ORDER OF GIVEN NUMBERS:\n ");
for(a=0;a<num;a++)
{
printf("%d\n ",array[a]);
}
getch();
}
OUTPUT:
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
No comments:
Post a Comment