Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions C++/Program-5/Readme.md
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions C++/Program-5/program.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
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 "<<sum;
return 0;
}