+ 2
Add all Even and Odd Numbers from the Entered Number
How to add even and odd number from entered number.
13 Respostas
+ 6
#include <iostream>
using namespace std;
int main() {
int i = 1, n, odd = 0, even = 0;
cin>>n;
while(i <= n){
if (i%2!=0)
odd += i;
else
even += i;
i++;
}
cout<<"Even sum:"<<even<<"\n";
cout<<"Odd sum:"<<odd;
return 0;
}
+ 2
it just adds 1 to the operand
e.g. i += 1 is same as i++
+ 2
Ask if you need any help.
Welcome :)
+ 1
Are you talking about range of numbers?
+ 1
like if I entered 5
1, 2, 3, 4, 5
odd-sum = 9
even-sum = 6
Is this what you want?
+ 1
I really dont know what while means even the sign ++,+=,+-, my prof focuses on smart students, he choose who to guide.
+ 1
a += b is equivalent to a = a + b
a -= b is equivalent to a = a - b
a++ or ++a increments the value of 'a' by 1
+ 1
What's the use of incrementing?
+ 1
Thanks for the Help!
0
my prof told us to use "while"
0
Yes
0
Thanks!