2 Answers
#include <stdio.h>
int main()
{
int a[20], n, i, temp = 0, j;
printf(“Enter number of array elements\n”);
scanf(“%d”, &n);
printf(“Enter array elements\n”);
for (i = 0; i < n; i++)
scanf(“%d”, &a[i]);
for (i = 1; i < n; i++)
{
for (j = 0; j < n – i; j++)
{
if (a[j] > a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
printf(“The sorted array is \n”);
for (i = 0; i < n; i++)
printf(“%d\n”, a[i]);
}