# ascending and descending order

• 03-20-2011
ssk
ascending and descending order
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."); }```
• 03-20-2011
There is no array[10] - it's 0 to 9 ONLY. :D

So no X=10, and no X<=10 either.

Please use code tags (click on the # in the advanced editor window and paste your code).

And Welcome to the forum, SSK!
• 03-20-2011
Mr.777
Kindly use code tags to write code... Thanks
• 03-25-2011
ssk
problem solved