This article describes about the program Sum of a digit in C/C++. Let us discuss about the digit sum or sub of a digit system.
Digit sum or Sum of a Digit
In mathematics the digit sum of a given integer is the sum of all its digits. That means the digit sum of 65001 is calculated as 6+5+0+0+1 = 12.
Program to Show Sum of a Digit
#include #include int main() { clrscr(); long a,k,n,p; cout<<"This program will show Sum of a given digit."<<endl<<endl; cout<<"What is the digit ?. Give a integer number or digit. "<<endl; cin>>a; n=a; p=0; while(a!=0) { k=a%10; p=p+k; a=a/10; } cout<<endl<<"Sum of given digit "<<n<<" is :"<<p; getch(); }
Thanks for such a nice article.