(C language) for loop doesn't work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

(C language) for loop doesn't work

this code should sum elements of 2D array put it doesn't give me the right answer =========================================== #include <stdio.h> main() { int total = 0; int k,i; int orders[5][2] = {{100,22},{220,33},{37,44},{16,55},{98,66}}; for (k = 0; k < 5; k++){ for(i=0;i<2;i++);{ total += orders[k][i]; } } printf("Total orders is %d\n", total); }

6th Oct 2020, 4:43 AM
saso yoo
saso yoo - avatar
2 Answers
+ 8
Because you added semicolon after the inner for loop.
6th Oct 2020, 4:46 AM
Mouli
Mouli - avatar
0
👌 Thanks
6th Oct 2020, 4:50 AM
saso yoo
saso yoo - avatar