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)
#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;
}
Comments
Leave a comment