confuse

adg
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>

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.