Answer to Question #299782 in C++ for Nancy

Question #299782

Write a program in C++ to print the sum of first 20 even numbers and odd numbers


separatel

1
Expert's answer
2022-02-19T11:24:17-0500








#include <iostream>




using namespace std;




int main() {
	int sumEven =0;
	int sumOdd =0;
	for(int i=0;i<=20;i++){
		if(i%2==0){
			sumEven+=i;
		}else{
			sumOdd+=i;
		}
	}


	cout<<"The sum of first 20 even numbers: "<<sumEven<<"\n";
	cout<<"The sum of first 20 odd numbers: "<<sumOdd<<"\n";


	system("pause");


	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

LATEST TUTORIALS
New on Blog