Try this code:
#include <iostream>
using namespace std;
int main()
{
int n,rem,s=0;
cout<<"Enter the digits :";
cin>>n;
while(n>0)
{
rem=n%10;
s=s+rem;
n=n/10;
}
cout<<"Sum of digits = "<<s<<endl;
return 0;
}
Your code didn't work because there was no ending line that is "endl" at line...
Sign up now and enjoy the perks of being a community member. It's free.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.