Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int digit(int num);
  8.  
  9. double total = 0;
  10.  
  11. int main()
  12. {
  13.     int n = 12345;
  14.     int answer = digit(n);
  15.     return 0;
  16. }
  17. int digit(int num)
  18. {
  19.     if (num % 10 >= 1)
  20.     {
  21.         total = total + (num % 10);
  22.         return digit(num / 10);
  23.     }
  24.     else
  25.     {
  26.         cout << total;
  27.         return 0;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement