Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int sum(int x)
- {
- if (x==0)
- {
- return 0;
- }
- else
- {
- return x%10 + sum(x/10);
- }
- }
- int main() {
- int x;
- cin >> x;
- cout << sum(x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement