C program to sort integer numbers in ascending order

This page has a C program to sort integer numbers in ascending order. The program has to get a set of integer numbers and then rearrange them in ascending order. To arrange the given integer numbers in ascending order, the program has to use a sorting algorithm. The below given C program to sort the integer numbers in ascending order using a sort algorithm. Kindly check out the program to print the given integer numbers in ascending order.

Program to sort integer numbers in ascending order

#include <stdio.h>

int main(){

int gn, p1, q1, excha, ascen[100];

clrscr();

printf("How many elements to sort :

");

scanf("%d", &gn);

printf("Enter the %d integer numbers :

", gn);

for (p1=1; p1<=gn; ++p1)

scanf("%d", &ascen[p1]);

for (p1=1; p1<=gn-1; ++p1)

{

for (q1=p1+1; q1<=gn; ++q1)

{

if (ascen[p1] > ascen[q1])

{

excha = ascen[p1];

ascen[p1] = ascen[q1];

ascen[q1] = excha;

}

}

}

printf("



The Sorted list of numbers in ascending order is . . .



");

for (p1=1; p1<=gn; ++p1)

printf("%d

", ascen[p1]);

getch();

return(0);

}

Sample output:





How many elements to sort : 6



Enter the 7 integer numbers : 41 -6 30 18 2 5



The Sorted list of numbers in ascending order is . . . -6 2 5 18 30 41