C program to arrange numbers inascending & descending order if else

C program to arrange numbers in ascending & descending order if else

This page has a C program to arrange numbers in ascending & descending order using if else. This program is designed to display the given numbers in ascending & descending order using if else statement. The program uses if . . . else statement for finding either ascending or descending order. For Example: If the given input numbers are  13 4 87 10 34 -34 28 then the program using if else statement will arrange the given numbers for ascending order as -34  4  10  13  28  34  87 and the program using if else statement will arrange the given numbers for descending order as  87  34  28  13  10  4  -34 .  The below given C program to print the given input numbers in ascending or descending order using if else. Kindly check out the program to arrange numbers in ascending & descending order.

Arrange numbers in ascending & descending order using if else

#include <stdio.h>
int main(){
int nr, p1, q1, select;
clrscr();
printf("How much numbers to sort : \n");
scanf("%d", &nr);
printf("Give %d  numbers one by one \n", nr);
for (p1=1; p1<=nr; ++p1)
printf("Select Your Option : 1 for Ascending and 2 Descending \n");
scanf("%d",&select);
if(select ==1)
{
for (p1=1; p1<=nr-1; ++p1)
for (q1=p1+1; q1<=nr; ++q1){
{
}
}
}
else if(select == 2){
for (p1=1; p1<=nr-1; ++p1)
for (q1=p1+1; q1<=nr; ++q1){
{
}
}
}
else {
printf("\n You Entered wrong Option");
getch();
exit();
}
printf("\n\nThe numbers arranged in order are . . . \n\n");
for (p1=1; p1<=nr; ++p1)
getch();
return 0;
}

Sample Outputs:

How much numbers to sort : 7

Give 7  numbers one by one  4  -2   1  10  5  7   -8

Select Your Option : 1 for Ascending and 2 Descending : 1

The numbers arranged in order are . . .

-8

-2

1

4

5

7

10

Related Popular Posts: