Underneath I have shared C++ program to discover the entirety of digits of a number.
For instance, a given number is 238 at that point aggregate of digits will be 13.
I am utilizing exceptionally straightforward rationale. On the off chance that we discover mod of any number by 10, at that point, the outcome is the last digit of the number. For instance, 123%10 is 3. Along these lines, I am extricating digits individually and adding to past entirety.
On the off chance that a number is partitioned by 10, at that point result is the number with the last digit evacuated. For instance, 123/10 is 12. Along these lines, I am expelling the digits individually from the end.
I have played out these activities inside while circle until the number isn’t equivalent to 0.
C++ Program to Find Sum of Digits of a Number
#include<iostream>
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
Enter any number:361
Sum of digits is:10