+ 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; }
4 odpowiedzi
+ 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.
+ 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'