Files
ARPZ_s1_pr4/alg_4_4.cpp

22 lines
356 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
int f(int n, int sum)
{
if (n == 0)
{
return sum;
}
return f(n / 10, sum + n % 10);
}
int main()
{
setlocale(LC_ALL, "Russian");
int n;
std::cout << "Введите число n для определения суммы его цифр: ";
std::cin >> n;
std::cout << "Сумма: " << f(n, 0);
}