It will be done using for loop and if else or any other method
Sum of even placed digits and odd placed digits
hi @kumarakash121005
u will have to use loops and if-else only to solve this problem…
refer this -->
#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;
}
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.