C program to accept N numbers and arrange them in an ascending order.
Code in C:
#include <stdio.h>
void main()
{
int i, j, t, n, a[30];
printf("Enter the value of the no. of elements : ");
scanf("%d", &n);
printf("Enter the numbers one by one : \n");
for (i = 0; i < n;i++)
scanf("%d", &a[i]);
for (i = 0; i < n;i++)
{
for (j = i + 1; j < n; j++)
{
if (a[i] > a[j])
{
t = a[i];
a[i] =a[j];
a[j] = t;
}
}
}
printf("The numbers arranged in ascending order are given below \n");
for (i = 0; i < n; ++i)
printf("%d\n", a[i]);
}
OUTPUT:
Comments
Post a Comment