Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int digit(int num);
- double total = 0;
- int main()
- {
- int n = 12345;
- int answer = digit(n);
- return 0;
- }
- int digit(int num)
- {
- if (num % 10 >= 1)
- {
- total = total + (num % 10);
- return digit(num / 10);
- }
- else
- {
- cout << total;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement