[IMG]
http://i52.tinypic.com/153npcx.jpg[/IMG]
my code is alright, but why it prints me this
-85893460
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include<stdio.h>
#include<stdlib.h>
#define N 20
void main()
{
int temp,j,i,ar[N];
printf("read 20 nums\n");
for
(i=1;i<N;i++)
scanf("%d\n",&ar[i]);
for (i=0;i<N-1;i++){
for (j = N-1;j >= i+1;j--){
if (ar[j] < ar[j-1])
{
temp = ar[j];
ar[j] = ar[j-1];
ar[j-1] = temp;
}
}
}
for (i=N;i >0;i--){
printf("%2d",ar[i]);
printf("\n");}
system("pause");
}
|
Last edited on
Because for an array of N elements - indexing starts at 0 and goes up to N-1
well, i changed it but still prints me the same
it's ok now, i put N-1 at the first for.... thank uou very much!!! ^_^
with that change it will print 19 numbers and no 20 which i want....
oops, I'll recheck
EDIT:
It displays 20 numbers for me (notice my code has i >=0 at the very last for loop - did you put thatchange in?)
Last edited on
i copy-paste your code and now it works.... i can't understand lol
thank you for your time