Is there any alternative way to solve this problem

#include
using namespace std;
int main() {
int r,s=0,t=0,n,c;
cin>>n;
c=n;
while(n!=0)
{
r=n%10;
s=s+r;
n=n/100;
}

while(c!=0)
{
    r=c%100;
    r=r/10;
    t=t+r;
    c=c/100;
}

cout<<s<<"\n" ;
cout<<t;

return 0;

}

Hi @abhishekpandeybhu_da87a9e0d2c73079
Ur approach is absolutely fine… the only way is to extract digits and then compute ans… u do the whole process using a single while loop only, no need for 2 loops…

Hey, is there anything else??

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.