Hi,
New to C and learning it from a book. Stuck at this problem. User enters 10 numbers then receives the option to either sort it in ascending or descending order. The output always shows an "0" that was never entered.
Code:
#include <stdio.h>
#include <stdlib.h>
//funtion prototye
void iInput();
void iSorting();
//global vaiable
int iArrary[10];
int main()
{
iInput();
iSorting();
}
void iInput()
{
int x;
for (x=0;x<10;x++)
{
printf("\n Enter #%d :",(x+1));
scanf("%d",&iArrary[x]);
}
}
void iSorting()
{
int x=0;
int y=0;
int z=0;
int iLargeN=0;
int iSmallN=0;
//system("cls");
printf("\n\n1\tSort numbers in Ascending order");
printf("\n2\tSort numbers in Descending order");
printf("\n\t Please enter your choise (1-2)");
scanf("%d",&y);
for (z=10;z>0;z--)
{
for(x=0;x<=10;x++)
{
if(iArrary[z]<iArrary[x])
continue;
else
{
iLargeN=iArrary[z];
iSmallN=iArrary[x];
iArrary[z]=iSmallN;
iArrary[x]=iLargeN;
printf("\n%d\t%d",iArrary[z],iArrary[x]);
}
}
}
if (y==1)
{
printf("\nNumbers in Decending Orders:");
for(x=0;x<=10;x++)
printf("\n %d",iArrary[x]);
}
else if (y==2)
{
printf("\nNumbers in Ascendin Order:");
for(x=10;x>=0;x--)
printf("\n %d",iArrary[x]);
}
else
printf(" Invalid Entry.");
}