Question: I created a code that sorts the numbers entered by the user in ascending order. However there is a bug in the code that arranges

I created a code that sorts the numbers entered by the user in ascending order. However there is a bug in the code that arranges those numbers in descending order instead.

Here is the code:

#include

int main ()

{

int number[30];

int x, y, a, n;

printf("Enter the size of array: ");

scanf("%d", &n);

printf(" ");

printf("Enter the numbers: ");

for (x = 0; x < n; ++x)

scanf("%d", &number[x]);

printf(" ");

for (x = 0; x < n; ++x)

{

for (y = x + 1; y < n; ++y)

{

if (number[x] < number[y])

{

a = number[x];

number[x] = number[y];

number[y] = a;

}

}

}

printf("Here are the numbers arranged in ascending order: ");

for (x = 0; x < n; ++x)

{

printf("%d ", number[x]);

}

Can you fix the bug?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!