Answer to Question #321178 in C++ for sanwal

Question #321178

Make a function which take an integer array and return sum of all even values.

(Note: Make array of 10 size in the main function)



1
Expert's answer
2022-04-09T17:55:53-0400
#include <iostream>
using namespace std;

int sumEven(int array[], int Size);
int main() {
    const int SIZE = 10;
    int array[SIZE]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
                
    cout<<"Sum: "<< sumEven(array, SIZE);
    
    return 0;
}

int sumEven(int array[], int Size)
{
    int sum = 0, i;
     for (i = 0; i < Size; i++)   {
        if (array[i]%2==0)
            sum = sum+array[i];
    }
    return sum;
}

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