Answer to Question #157760 in C++ for yafet

Question #157760

 Add the even numbers between 0 and any positive integer number given by the user.


1
Expert's answer
2021-01-23T10:19:05-0500
#include <iostream>
using namespace std;


int main(){
	int n;
    cin >> n;
    int sum = 0;
    for(int i = 0; i <= n; i++)
    {
        if(i%2 == 0)
            sum+=i;
    }
    cout << 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
APPROVED BY CLIENTS