128. 陣列加總

 avatar
user_6817964
c_cpp
2 years ago
398 B
1
Indexable
Never
int mysum(int* a, int size);
int mysum(int* a, int size) {
    int sum = 0;
    for (int i = 0; i < 4; i++) {
        sum += *a;
        a++;
    }
    return sum;
}

int main() {

    int data[4] = {};
    for (int i = 0; i < 4; i++) {
        scanf("%d", &data[i]);
    }
    int size = sizeof(data) / sizeof(data[0]);
    printf("%d\n", mysum(data, size));

    return 0;

}