64 506
Assignments Done
99,1%
Successfully Done
In September 2018

Answer to Question #15275 in C++ for Bill Jovan

Question #15275
program that will accept a number n and display the sum of all even numbers and the sum of all odd numbers from 1-n
Expert's answer
#include <iostream>
using namespace std;
int main (){

int n;

cout<<"Enter number n please!\n";

cin>> n ;

int sumEven, sumOdd;
sumOdd = sumEven = 0;
for (int i = 0 ; i <= n ; i++){
& if (i%2 == 0) sumEven+=i;
& else sumOdd+=i;
}
cout<< "Sum even number from 1 to n: "<<sumEven<<endl;
cout<< "Sum odd number from 1 to n: "<<sumOdd<<endl;

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions