Cant solve the problem

Hi im not able to solve the problem im not able to understand how i can know whether its on even place or odd can u help me out?

hi @dharamrajroy_275ef8688612039e
refer this code–>

#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;

    int pos = 1;
    int odd_sum = 0;
    int even_sum = 0;

    while(n > 0){
        int x = n%10;
        n = n/10;
        if(pos%2 == 1){
            odd_sum += x;
        }
        else{
            even_sum += x;
        }
        pos++;
    }
    cout<<odd_sum<<endl;
    cout<<even_sum<<endl;
}

hey, if still there is anything do let me know…

no all good thank you for the help

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like

done thanks for help

also i had to ask what does this line do

int x = n%10;
n = n/10;

int x = n%10;
This line extracts the digit.
n = n/10;
This line removes that digit from the number.

what what if the number is of 3 digits

That’s why we have put a while loop so that all digits can be extracted one by one…