This C++ program can find the sum of digits of a number. User needs to enter a number for example, take number xyz. Why user enters this number, computer will say, the answer is x+y+z.
For example if the number is 101, the result should be 1+0+1 ie, 2.
Program to Find Sum of Digits
#include<iostream.h>
#include<conio.h>
Int main()
{
int n,temp,s=0;
cout<<“Enter Your Number: “;
cin>>n;
while(n>0)
{
a=n%10;
n/=10;
s+=a;
}
cout<<“Sum of Digits: “<<s;
getch();
Return(0);
Output
Enter Your Number: 101
Sum of Digits: 2
Leave a Reply