HEllo. i wrote those functions which look like recursive functions but i'm not satisfied i feel like it's not recursive, is there a way to write only one recursive function to do both jobs? or two functions but in a "real" recursive way ?
thank you first of all.
actually it worked for me with those two functions with any number i even entered 10 digits and it worked but i wanted a simple recursive function to do the job, my functions were more like a normal function.
#include <iostream>
int sum_first_and_last(unsignedlong n, int top = 1)
{
return n < 10 ? n : sum_first_and_last(n / 10, 0) + n % 10 * top;
}
int main()
{
std::cout << sum_first_and_last(31234567890123456) << '\n';
}