+2 votes
in Class 12 by kratos

Write a program to find the sum of all the digits of a number using while statement.

1 Answer

+3 votes
by kratos
 
Best answer

include<iostream.h>

include<iomainp.h>

void main()

{

int n,temp,sum = 0,reminder;

cout<<"Enter any positive whole number";

cin>>n;

temp = 1;

while(temp! = 0)

{

remainder = temp % 10;

sum = sum + reminder;

temp = temp/'0;

}

cout <<"The sum of digits of "<<n<<"is"<<sum<<endl;

}

...