+ 1

Anyone to help me understand this c language code.

This loop variable (m) is so confusing. *sum of array*/ #include <stdio.h> int main(){ int m; int n[5]; int sum; for(m=0;m<=4;m++){ printf("Enter a value:\n"); scanf("%d",&n[m]); } for(m=0;m<=4;m++){ sum=sum+n[m]; } printf("\nThe sum of the elements is:%d",sum); return 0; }

30th Jan 2020, 5:47 PM
Wadika
Wadika - avatar
4 ответов
+ 2
m is defined outside of the loops, it then is equaled to 0 and is then looped 5 times. Then it is reset in the next for loop (to 0 again) and is looped 5 times.
30th Jan 2020, 5:56 PM
Gevork Bagratyan
+ 1
If you are also confused about how m is used within these for loops: M is being incremented each loop and in this case is looking through the array 'n'
30th Jan 2020, 5:58 PM
Gevork Bagratyan