0

C++

Write a C-program that finds and prints the sum of even and odd integers from 2 to 30 separately by using the switch selection.

24th Jan 2017, 12:27 PM
Kirshan Singh Rajput
Kirshan Singh Rajput - avatar
2 ответов
0
why not try loops
5th Feb 2017, 8:13 PM
Elijah
Elijah - avatar
0
I am not sure if this answers your question. This works... #include <iostream> using namespace std; int main() { int x,evenSum =0,oddSum=0; for (x=2;x<=30;x++) { int i; i=x%2; switch(i) { case 0: evenSum+=x; continue; case 1: oddSum+=x; continue ; } } cout << "Sum of even numbers from 2 to 30 "<<evenSum<<endl; cout << "Sum of odd numbers from 2 to 30 "<<oddSum<<endl; return 0; }
9th Feb 2017, 10:47 PM
CodeVP
CodeVP - avatar