Answer to Question #155249 in C for Bonface

Question #155249

Write a function int solution(int A[], int that given an array A consisting of N integers, returns the sum of all integers which are multiples of 4


1
Expert's answer
2021-01-13T08:13:35-0500
#include <stdio.h>

int solution(int A[], int N) {
    int result = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] % 4 == 0)
            result += A[i];
    }
    return result;
}


int main() {
    int nums [16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
    printf("%d", solution(nums, 16)); // 4 + 8 + 12 + 16 = 40
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS