C Program to Sort the Array in an Ascending Order
#include <stdio.h>
int main()
{
int i, j, a, n, array[30];
printf("Enter the number of elements\n");
scanf("%d", &n);
printf("Enter the elements \n");
for (i = 0; i < n; ++i)
scanf("%d", &array[i]);
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (array[i] > array[j])
{
a = array[i];
array[i] = array[j];
array[j] = a;
}
}
}
printf("The ascending order of elements is: \n");
for (i = 0; i < n; ++i)
printf("%d\n", array[i]);
return 0;
}
#include <stdio.h>
int main()
{
int i, j, a, n, array[30];
printf("Enter the number of elements\n");
scanf("%d", &n);
printf("Enter the elements \n");
for (i = 0; i < n; ++i)
scanf("%d", &array[i]);
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (array[i] > array[j])
{
a = array[i];
array[i] = array[j];
array[j] = a;
}
}
}
printf("The ascending order of elements is: \n");
for (i = 0; i < n; ++i)
printf("%d\n", array[i]);
return 0;
}