toiyeunmlt
NguyenAnhQuan
c_cpp
2 years ago
303 B
10
Indexable
#include <iostream>
using namespace std;
int calc(int n)
{
if (n < 10) return n;
return calc(n / 10) + (n % 10);
}
void sum(int n, int &s)
{
s = calc(n);
}
void input(int &n)
{
cin >> n;
}
int main()
{
int n, s=0;
input(n);
sum(n, s);
cout << s;
}
Editor is loading...