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
1
Expert's answer
2012-09-25T11:32:57-0400
#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;
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment