0
What is the problem ?!
so I wrote this program i#include <stdio.h> int main() { int i,k,j,n,c,h; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); for (j=0;j<n;j+=2) { h = j+1; c = a[j]; a[j] = a[h]; a[n] = c; } for(k=0;k<n;k++) printf("%d\n",a[k]); return 0; } it's suppose when I enter a group of numbers it will change every number with the one next to it like 👉 {123456}_>{214365} but instead of That it just give me zero or the addresses
8 ответов
+ 6
can we see the code via the playground as it may help us help you
+ 2
Inside your second for loop, the for(j = 0; ...)
Replace:
a[n] = c;
With:
a[h] = c;
Hth, cmiiw
+ 2
and everytime I get this 👇
0
123456
0
2358772
0
4593840
+ 2
Taw🐼 that's odd, I am running your code but we have different output, I'll look it up again later tomorrow, now I'm too sleepy. Good luck mate ...
+ 1
I already tried that but it didn't work the same result without infinite loop
+ 1
OK the problem was in the way I enter the numbers😅
now I have the right output
thanks for your help 👍
0
https://code.sololearn.com/ctx6HDx7UQj7/?ref=app
here you are 🌚
0
Taw🐼 I run the code with this input in Code Playground. The first 6 is the array size, next I used 1 to 6 to fill array.
6
1
2
3
4
5
6
Output:
2
1
4
3
6
5