diff --git a/C++/Program-5/Readme.md b/C++/Program-5/Readme.md new file mode 100644 index 00000000..4d9e8c08 --- /dev/null +++ b/C++/Program-5/Readme.md @@ -0,0 +1,13 @@ +Program 5 + +Write a program to find the sum of the digits of the given number. + +Variable description-- + +n=Number + +sum= Holds the sum + +rem=Holds the single digit of the number + +temp=Temporarily holds the value of n diff --git a/C++/Program-5/program.cpp b/C++/Program-5/program.cpp new file mode 100644 index 00000000..7d1c929f --- /dev/null +++ b/C++/Program-5/program.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main() { + cout<<"enter the number\n"; + int n; + cin>>n; + int temp, rem, sum = 0; + temp = n; + while(temp>0) + { + rem = temp%10; + temp = temp/10; + sum+=rem; + } + cout<<"\nThe sum is "<