Advertisement Remove all ads

# Write a Program to Sort Given Array in Ascending Order. - Structured Programming Approach

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;
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…?5Enter the numbers.31456200150The numbers arranged in ascending order are given below13150200456
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
Share
Notifications

View all notifications

Forgot password?