Sorry newbie here! Pls bear...
Yeah I want the user to enter 10 digits, stored in arrays. Arary is then sorted in descending order(using functions is possible). Then using another function display the sorted array.
Sorry newbie here! Pls bear...
Yeah I want the user to enter 10 digits, stored in arrays. Arary is then sorted in descending order(using functions is possible). Then using another function display the sorted array.
I wontOriginally posted by Unregistered
Sorry newbie here! Pls bear...
I think it's a better idea to show what you have done... The way you are asking is like asking someone to do homework for you...
You show what you have done and sure the ppl here will not hesitate to help you solve the problem(s) you are facing...
It's unfulfilled dreams that keep you alive.
//netboy
Aahhhhh sh|t! The program crashed!
Ggrrr... I'd post up, what I have done as soon as I re-type it. My problem was the sorting in descending order part. I don't get how to do it(I tried). I thought it would've worked, but since it crashed I guess not.
Have you tried qsort?
-Prelude
My best code is written with the delete key.
How about sorting is the normal way (acsending) and then printf it the other way round so that it will be displayed in desending order?
It's unfulfilled dreams that keep you alive.
//netboy
I am not sure if even this works, but I would appreciate it if someone would flame me to the right direction... IF necessary.Code:. . . for(counter = 1; counter <=10; ++counter) { printf("\nEnter 10 numbers: "); scanf("%d", &a[counter]); } .
Also I don't even know how to sort an array(ascendingly) so I wouldn't know how to follow netboy's method.
Prelude, I am required to use a function to sort it(if it's at all possible) and try not to involve pointers, so your suggested method I'm gonna keep as a last resort. Anyway, I did a little search on some C sites and came up with the below code for sorting.
I don't really know how to implement it seeing as how I won't know the MAX value either.Code:/* bubble sort the array */ for (x=0; x < MAX-1; x++) for (y=0; y < MAX-x-1; y++) if (a[y] > a[y+1]) { t=a[y]; a[y]=a[y+1]; a[y+1]=t; } /* print sorted array */ printf("--------------------\n"); for (i=0; i < MAX; i++) printf("%d\n",a[i]);
>I don't really know how to implement it seeing as how I won't know the MAX value either.
MAX is the number of elements in the array (in your cause 10 I presume).
In the bubble sort code, "a" is the array, which just happens to have the same name as your array
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
why dont you replace MAX by 10 and try to understand what the code is doing ?