+ 1
How its sum becomes 6? Can someone explain?
int array[2][2]={0,1,2,3}; int i=0,sum=0; for(i=0;i<4;i++) { int x,y; x=i%2; if (x){ y=0; } else{ y=1; } sum+=array[x][y]; } printf("%d", sum);
3 odpowiedzi
+ 3
Bikesh,
Add this line before adding array[x][y] to <sum>. It might just give you an dea.
printf("adding array[%d][%d] (%d) to <sum> -> %d\n", x, y, array[x][y], sum + array[x][y]);
+ 2
I am getting 0 how you are getting 6?
https://code.sololearn.com/cB3Qr187t1lK/?ref=app
+ 2
Ohh sorry! I just forget to put the values in curly brackets.
Now it's corrected. Try once again.