answer)
#include <iostream>
using namespace std;
int main()
{
int reminder,sum,number;
while(1)
{
cout<<"Enter a number :";
cin>>number;
sum=0;
if(number==0)//break the loop when input is zero
{
break;
}
while(number!=0)
{
reminder=number%10;//taking reminder of number
sum=sum+reminder;//add remainder to sum variable
number=number/10;
}
cout<<"Sum of digits "<<sum<<endl;
}
return 0;
}
output:
Enter a number :123
Sum of digits 6
Enter a number :454
Sum of digits 13
Enter a number :23
Sum of digits 5
Enter a number :0
Get Answers For Free
Most questions answered within 1 hours.