0

How to get sum of even and odd number separately using while loop

Using While loop is mandatory . Range should be decided by user

2nd Dec 2019, 7:56 PM
Ayush Khandelwal
Ayush Khandelwal - avatar
6 Answers
+ 3
It's simple. Just check if n%2 == 0 evenSum+= n else oddSum += n
2nd Dec 2019, 8:00 PM
AÍąJ
AÍąJ - avatar
+ 3
Mirielle, by using your code with range 1,11 (means using 1 including 10), the result of even is 30 and odd is 24. Shoud odd not be 25?
3rd Dec 2019, 10:33 AM
Lothar
Lothar - avatar
+ 2
Ayush Khandelwal, have you done a try to solve this task before asking here? It would be nice if you can share it with us.
2nd Dec 2019, 8:21 PM
Lothar
Lothar - avatar
+ 2
here is an other sample with range and while: https://code.sololearn.com/ck74DhRwXDSJ/?ref=app
3rd Dec 2019, 10:18 AM
Lothar
Lothar - avatar
0
what programming language? and what range of numbers?
2nd Dec 2019, 7:58 PM
Bahha┣
Bahha┣ - avatar