I’m trying to alternate array elements high to low sequence.It’s half working correctly and then work normally(low to high).I can’t figure out the problem,Can you please help me?
My code:
#include <stdio.h>
int main()
{
int ara[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
int i, j, temp;
for(i = 0,j = 9; i < 10; i++,j--){
temp = ara[j];
ara[j] = ara[i];
ara[i] = temp;
}
for(i = 0; i < 10; i++){
printf("%d\n", ara[i]);
}
return 0;
}
My output:
100
90
80
70
60
60
70
80
90
100
Process returned 0 (0x0) execution time : 0.016 s
Press any key to continue.
Expected Output should be like:
100
90
80
70
60
50
40
30
20
10
Process returned 0 (0x0) execution time : 0.016 s
Press any key to continue.