I have this program I've been working on in this c book I have and it wants me to sort numbers in ascending or descending order I think I can figure out the descending anyway I know that I might have to use an if statement but maybe not I have this worksheet from when I took c# that has the code to sort in descending order so I think I can figure that out here is my lame attempt it doesn't sort I'm trying to well I know what it does it just prints 10 10 times I know I have to compare the array 0 with array 1 then which ever is bigger then print that first I think but I can't figure out what to do heres my code
Code:#include <stdio.h> #include <stdlib.h> void SortAscending(void); void SortDescending(void); int iArray[9]; int x; int main() { int iChoice = 0; for (x = 0; x < 10; x++) { printf("\n\tEnter ten numbers: "); scanf("%d",&iArray[x]); } system("cls"); printf("\n\tEnter sorting method\n"); printf("1\tAscending order\n"); printf("2\tDescending order\n"); printf("Enter number: "); scanf("%d",&iChoice); if (iChoice == 1) SortAscending(); else if(iChoice == 2) SortDescending(); } void SortAscending() { for(x = 0; x < 10; x++) if (iArray[x] >= iArray[x]+x) printf("%d\n",iArray[x]); else printf("%d\n",iArray[x]+x); } void SortDescending() { }



LinkBack URL
About LinkBacks




