1. ## Arrays, descending orders

Hello,
This is the program that I need to do:
Write a program that will sort an array of 20 integer numbers into descending order. The results must be displayed on the screen
in one column.

I tried this, me totally confuse.
I tried to do this program for one whole day, done flowchart... could not do it. Or it is me or the program.
If someone could help.
Thanks.

Code:
```#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main()
{
int a[20];
int i, p, j, sum, lar,sma, an, lar1, lar2; /*i for the number and p for the association of th number*/

i=0;
sum=0;
lar=0;
sma=100000;
do{
printf(" Enter %d:",i);
scanf("%d",&p);     /*I use p as my input*/
a[i] = p;     /*I use i for my Array*/
i=i+1;
if(p>lar)
lar=p;
if(p<lar && !=lar)
lar1=p;
if (p<lar1 && !=lar1)
lar2=p;

}while(i<20);
j=i;
i=0;
do{
printf("a[%d] = %d\n", i, a[i]);
i=i+1;
}while(i<j);     /*I use J as my bonus*/
printf("\n\nThe sum of all this arrays is %d",sum);
printf("\nThe largest number is %d",lar);
printf("\nThe smalest number is %d",sma);
getch();

}
```

2. You should read in ALL your data, and then sort it. Look up Bubble Sort to get your first taste of sorting. How many extra variables do you plan on creating to do comparisons with? Really, don't do it that way.

3. Thanks,
I did not understand, what you said. "taste of sort"
Im very confuse. Brain gonna explode lol
Can you guide me or something. What can I do?

4. What I meant was, there are many sorting algorithms, but for you Bubble Sort will do. If you've never dealt with sorting before, it will give you an idea of what is involved.
This should get you started...
Bubble Sort and Modified Bubble Sort - Cprogramming.com

5. "do you plan on creating to do comparisons with? Really, don't do it that way." I was planning to do more comparisons to finish the program. I read the sort things, they never teach me in class sort. Dont really understand it. I look at the code of the bubble sort, it confuse me more. lol. sorting algorithms able you to play with the arrays?

6. I don't know why the last bit is wrong. :|
Everthing is in order except a number. The number is 84. :|

Code:
```/* 	 Write a program that will sort an array of 20 integer numbers into
descending and ascending order. The results must be displayed on the screen
in two side by side columns.

*/

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main()
{
int a[20] = {15, 21, 20, 10, 32, 41, 21, 32, 65, 69, 98, 54, 65, 58, 57, 69,57 ,14,15,84};
int j, i, temp;
int n=0;
int x = 0;
int y =1;

while(n<20)
{
for(int x=0; x<n; x++)

{

for(int y=0; y<n-1; y++)

{

if(a[y]<a[y+1])

{

temp = a[y+1];

a[y+1] = a[y];

a[y] = temp;

}

}

}

++x;
++y;

n++;
}                  //go back and do 20 more loops with the if statement.

i=0;
do{
printf("a[%d] = %d\n", i, a[i]);
i=i+1;
}while(i<20);								/*I use J as my bonus*/

getch();

}```

7. What's with this while( n < 20 ) and n++ business? Just set n = 20, or better yet, if you're hard coding the array, use a #define. Look at what the code you copied is doing and the logic behind it. Why does the outer loop go up to the array_size -1? And why the inner loop goes up to the array_size -2. Then, you'll be able to answer why 84 got left behind.

Don't re-declare variables in a loop, i.e. for( int i = ... In fact, don't declare variables in the middle of your code.

8. -When I mix two program in one to give me this, I forgot to delect the while loop.
-I have delected the int from the for loop.
-I understood the if function of bubble sort, need to think about the two loop tomorrow.
Thanks for the help, I got the output right .

Have you got a good link or a good book to buy to improve my programming skill, because I got 1 month free and I want to learn a lot
anyway Thanks for the help.

9. C Book Recommendations

Can't go wrong with Kernighan and Ritchie's The C Programming Language (although some syntax changes since last publish)