Answer to Question #151711 in C++ for haroon

Question #151711
Find_Selective_even” should input two values (P and Q) from the user. After that, function “Find_Selective_even” should calculate sum of all those even elements which are between P and Q. index In the end, the calculated sum is returned to the main program.
1
Expert's answer
2020-12-17T13:29:29-0500
#include <iostream>
using namespace std;
void Find_Selective_even () {
    int P, Q;
    cout << "P must be less than Q" << endl;
    cout << "Enter P: "; cin >> P;
    cout << "Enter Q: "; cin >> Q;
    int Sum = 0;
    for (int i = P + 1; i < Q; i++) {
        if (i % 2 == 0) {
            Sum += i;
        }
    }
    cout << "The sum between even numbers between P and Q is:" << Sum;
} 
int main () {
    Find_Selective_even();
    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