SHARE
TWEET

Untitled

a guest Dec 16th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pch.h"
  2. #include <iostream>;
  3. #include <locale>;
  4. #include "windows.h";
  5.  
  6. int sum(int n){
  7.     if (n / 10 != 0) {
  8.         return n % 10 + sum(n / 10);
  9.     }
  10.     else {
  11.         return n % 10;
  12.     }  
  13. }
  14.  
  15. int main()
  16. {
  17.     SetConsoleOutputCP(1251);
  18.     using namespace std;
  19.     int a;
  20.     cout << "Введіть число: ";
  21.     cin >> a;
  22.     a = sum(a);
  23.     cout << "Сума цифр: " << a << endl;
  24.     return 0;
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top