111k views
3 votes
Write a function that receives an integer list from STL and returns the sum of even numbers in the list (return zero if no even number is in the list)

User Pvinis
by
8.6k points

1 Answer

4 votes

Answer:

int sumeven(int lis[],int n)

{

int sum_e=0;//integer variable to store the sum.

for(int i=0;i<n;i++)

{

if(lis[i]%2 == 0)//if the number is even adding to sum_e.

sum_e=sum_e+i;

}

return sum_e;//retuning the sum.

}

Step-by-step explanation:

The above written function is in C++.This function find the sum of even numbers in the list provided.It loops over the array and if the number is even adds to the variable sum_e finally return sum_e which having the sum of even numbers now.

User Nirro
by
8.1k points