}

**C++ code to get sum of all odd and even numbers in given range**

#include<iostream>

int main(){

int number;

int min,max;

long odd_sum =0,even_sum = 0;

cout << "Enter the minimum range:
";

cin
>> min;

cout << "Enter the maximum range:
";

cin
>> max;

for(number = min;number <= max; number++)

if(number % 2 != 0)

odd_sum = odd_sum + number;

else

even_sum = even_sum + number;

cout
<< "Sum of even numbers in given range
is: " << even_sum << endl;

cout
<< "Sum of odd numbers in given range
is: " << odd_sum;

return 0;

}

## 2 comments:

very helpful

This is so amazing that you have shared the C++ code to get a sum of all odd numbers in a given range. This will help me a lot. Thanks for sharing this with us. I really appreciate that. Now it's time to avail 1 litre bottle for more information.

Post a Comment