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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started