-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4db3c42
commit c68c1bc
Showing
1 changed file
with
5 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
// C++ program to compute sum of digits in | ||
// number. | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
/* Function to get sum of digits */ | ||
class gfg { | ||
class addSum { | ||
public: | ||
int getSum(int n) | ||
{ | ||
int sum = 0; | ||
int total = 0; | ||
while (n != 0) { | ||
sum = sum + n % 10; | ||
total = total + n % 10; | ||
n = n / 10; | ||
} | ||
return sum; | ||
return total; | ||
} | ||
}; | ||
|
||
// Driver code | ||
int main() | ||
{ | ||
gfg g; | ||
addSum g; | ||
int n = 687; | ||
|
||
// Function call | ||
cout << g.getSum(n); | ||
return 0; | ||
} | ||
// This code is contributed by Soumik |