Working on another ide, even odd sum

#include
using namespace std;
int main() {
int num;
int odd=0;
int even=0;
cin>>num;
while(num!=0)
{
even=even+num%10;
num=num/10;
odd=odd+num%10;
num=num/10;
}
cout<<odd<<endl;
cout<<even<<endl;
return 0;
}

Your code is correct, it is just that sum of odd place digits is getting summed up in ‘even’ and sum of even place digits is getting summed in ‘odd’ variable. And, you need to print sum of odd place digits followed by even place digits.

1 Like