Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
275 B
0
Indexable
Never
#include <iostream>
using namespace std;
int digitSum(int k) 
{
    if (k == 0) 
    {
        return 0;
    }
    else 
    {
        return k % 10 + digitSum(k / 10);
    }
}
int main() 
{
    int k;
    cin >> k;
    cout << digitSum(k);
    return 0;
}
Leave a Comment