HomeC++

C++ Program to Find Sum of Digits of a Number

C++ Program to Find Sum of Digits of a Number
Like Tweet Pin it Share Share Email

Try to make Simple C++ Program to Find Sum of Digits of a Number.Now Make it.

C++ Program to Find Sum of Digits of a Number

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
unsigned long i,p,n,sum=0;
cout<<"Enter any Number:";
cin>>n;
while(n!=0)
{
p=n%10;
sum+=p;
n=n/10;
}
cout<<endl<<"Sum of digits is:"<<sum;
return 0;
}

Output of ProgramC++ Program to Find Sum of Digits of a Number

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *