Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement