76 820
Assignments Done
Successfully Done
In June 2019

Answer to Question #15342 in C++ for reymark

Question #15342
write a program that will accept a number n and display the sum of all even numbers and the sum of all odd numbers from 1 to n.
Expert's answer

bool even(int n){
if (n%2==0) return true; else return 0;

int sumOdd=0, sumEven=0;

void main(){
int m;
cout<<"Enter an integer: ";
for (int i=0; i<=m; i++)
& if (even(i)) sumEven += i;
& else sumOdd += i;
cout<<"Sum of even numbers: "<<sumEven<<"\nSum of odd numbers: "<<sumOdd<<"\n";

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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions