|
If we complement the if condition in this program, it will
give out the sorted array in descending order.
Sorting can also be done in other methods, like
selection
sorting and
insertion
sorting, which follows in the next pages. #include<stdio.h>
void main()
{
int A[20], N, Temp, i, j;
clrscr();
printf("\n\n\t ENTER THE NUMBER OF TERMS...: ");
scanf("%d",&N);
printf("\n\t ENTER THE ELEMENTS OF THE ARRAY...:");
for(i=1; i<=N; i++)
{
gotoxy(25, 11+i);
scanf("\n\t\t%d",
&A[i]);
}
for(i=1; i<=N-1; i++)
for(j=1; j<=N-i;j++)
if(A[j]>A[j+1])
{
Temp = A[j];
A[j] = A[j+1];
A[j+1] = Temp;
}
printf("\n\tTHE ASCENDING ORDER LIST IS...:\n");
for(i=1; i<=N; i++)
printf("\n\t\t\t%d",A[i]);
getch();
}
Download exe and source code here.
Related source codes :
Program to sort the numbers
using Insertion sort
Program to sort the numbers
using Selection sort
Select program from the list |