Write a program to sort given array in ascending order.

Advertisement Remove all ads

#### Solution

Program :-

Source code :

```
//Program to sort given array in ascending order
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, a, n, array[50];
printf("How many numbers in an array…? \n");
scanf("%d", &n);
printf("Enter the numbers. \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 (number[i] > number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("The numbers arranged in ascending order are given
below \n");
for (i = 0; i < n; ++i)
printf("%d\n", number[i]);
getch( );
}
```

Output :

How many numbers in an array…? 5 Enter the numbers. 3 1 456 200 150 The numbers arranged in ascending order are given below 1 3 150 200 456 |

Concept: Array

Is there an error in this question or solution?

Advertisement Remove all ads

#### APPEARS IN

Advertisement Remove all ads

Advertisement Remove all ads