Thursday, 4 November 2021

C Program to find ascending and descending order of given number

C Program to find ascending and descending order of given number

Program

#include<stdio.h>

#include<conio.h>

void main()

{

 Int num[10],i,j,temp;

clrscr();

printf("\n Enter 10 values of an array.....\n");

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

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

printf("\n array before sort ....\n");

for(i=0;i<10;i++) printf("%d\t",num[i]);

for(i=0;i<9;i++) { for(j=i+1;j<10;j++)

 {

 if(num[i]<num[j])

{ temp=num[i];

num[i]=num[j]; num[j]=temp;

 }

 }

}

 printf("\n array after sort .........\n");

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

printf("%d\t",num[i]); getch();

}

 

 

 

Output:

 

Enter 10 values of an array:

5 4 8 7 2 3 9 6 0 1

 

Array before sort: 5 4 8 7 2 3 9 6  0 1

 

Array after sort: 9 8 7 6 5 4 3 2 1 0

 

No comments:

Post a Comment

google-site-verification: google18ae80885fc3d876.html