I have written a different code but it is not working. The code is below please fix it

#include
using namespace std;

int main ()
{
int n;
int i=1;
int sum=0;
int o=n/i;
cin>>n;
int l=o%10;
while (n%i!=0){
sum=sum+l;
i=10*i;

}
cout<<"Sum of the digits=";
cout<<sum;

return 0;

}

hi,
i have corrected ur code --> https://ide.codingblocks.com/s/642216

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.