Ask Question

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)

+5
Answers (1)
  1. 2 February, 06:14
    0
    int sumeven (int lis[], int n)

    {

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

    for (int i=0; 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.

    }

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers