QUESTION: - Program to Sort the user input value in ascending order.
Program
#include <stdio.h>
#include <conio.h>
void main()
{
int num[10], i, j, temp, no;
printf("enter any 10 number in an array: ");
for (i = 0; i < 10; i++)
{
scanf("%d", &num[i]);
}
// sorting the elements
for (i = 0; i < 10; i++)
{
for (j = i + 1; j < 10; j++) // i+1 means increase the array in increasing order.
{
if (num[i] > num[j])
{
temp = num[i];
num[i] = num[j];
num[j] = temp;
}
}
}
// display
printf("the sorted number in array are: ");
for (i = 0; i < 10; i++)
{
printf("%d ", num[i]);
}
}
OUTPUT
Enter any 10 number in an array: 1 4 7 8 9 5 6 63 2 4
the sorted number in array are: 1 2 4 4 5 6 7 8 9 63
Follow our page for regular updates.
0 Comments