How would I add a loop to print the output of the following code both in ascending and descending order? First off, here was the Problem:
Build a C program (not C++) that uses a single-dimension array to store 10 numbers input by a user. After inputting the numbers, the user should see a menu with two options to sort and print the 10 numbers in ascending or descending order.
Here is my code so far:
Code:
#include<stdio.h>
int main()
{
int arry[10], y,n,tmp,x,j,i;
printf("\nEnter 10 numbers:\n");
for(x=1;x<=10;x++)
{
scanf("%d",&arry[x]);
}
printf("\n[Enter your choice]:\n");
printf("\n1. Acending order: \n2. Decending
order\n \n");
scanf("%d",&y);
if(y==1)
{
for (i=1; i<n; i++)
{
for (j=n; j>i; j--)
{
if (arry[j] < arry[j-1])
{
tmp = arry[j];
arry[j] = arry[j-1];
arry[j-1] = tmp;
}
}
}
}
else
{
for (i=1; i<n; i++)
{
for (j=n; j>i; j--)
{
if (arry[j] > arry[j-1])
{
tmp = arry[j];
arry[j] = arry[j-1];
arry[j-1] = tmp;
}
}
}
}
return 0;
}