### confuse

Last edited on
 what is the need of declaring the "m" and "n". i suppose alement in array have already been declare as 'a' and 'b'.

I'm assuming you're asking if loop variables a nd b could be reused where m and n are used. Yes, a and b could be reused since a and b are not in use at the point where m and n are used.

PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes your code easier to read and it makes it easier to respond to you post.
Last edited on
tq very much
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` ``````#include int arrayA[10]; int arrayB[10]; void readData() { int i; // it is enough one variable for all for loops inside one function printf("Please enter 10 integer into Array A : \n"); for(i=0; i<10; i++) scanf("%d",&arrayA[i]); printf("\nPlease enter 10 integer into Array B : \n"); for(i=0; i<10; i++) scanf("%d",&arrayB[i]); } void printLarger() { int i; // it is enough one variable for all for loops inside one function int sumArrayA = 0; int sumArrayB = 0; for(i=0; i<10; i++) sumArrayA += arrayA[i]; for(i=0; i<10; i++) sumArrayB += arrayB[i]; if(sumArrayA > sumArrayB) { printf("\narrayA is larger than arrayB\n"); printf("\nData in arrayA : "); for(i=0; i<10; i++) printf("%d ",arrayA[i]); printf("\n\nSum for arrayA is : "); printf("%d",sumArrayA); } else { printf("\narrayB is larger than arrayA\n"); printf("\nData in arrayB : "); for(i=0; i<10; i++) printf("%d ",arrayB[i]); printf("\n\nSum for arrayB is : "); printf("%d",sumArrayB); } } int main() { printf("---------------------------------------\n"); printf("Please insert data into Array 1 by 1\n\n"); printf("---------------------------------------\n"); readData(); printLarger(); printf("\n\nEnd of Program\n\n"); return 0; } ``````
For the benefit of other forum users it would be polite to not delete your original posts once you have your solution.
Topic archived. No new replies allowed.