67 048
Assignments Done
99,3%
Successfully Done
In November 2018

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
#include<iostream.h>

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: ";
cin>>m;
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions