Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>;
- #include <locale>;
- #include "windows.h";
- int sum(int n){
- if (n / 10 != 0) {
- return n % 10 + sum(n / 10);
- }
- else {
- return n % 10;
- }
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- using namespace std;
- int a;
- cout << "Введіть число: ";
- cin >> a;
- a = sum(a);
- cout << "Сума цифр: " << a << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement