0

The reversed number Recursively

Hello SoloLearn! I am strugling with a problem if I may ask: How can i print the reversed number of n using a recursive function. I need it to return the reversed number through the name of the function (not using a variable).This is my attempt, but it returns the exact same number :) #include <iostream> #include <math.h> using namespace std; int oglindit(int n){ if(n<10) return n; else return oglindit(n/10)*10+(n%10); } int main() { int n; cin>>n; cout<<oglindit(n); return 0; } Thank you for your time!

26th Nov 2018, 10:14 AM
Stefan Secrieru
Stefan Secrieru - avatar
5 ответов
26th Nov 2018, 11:21 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
+ 8
return (n%10)*pow(10, (int)log10(n)) + oglindit(n/10);
26th Nov 2018, 11:29 AM
Mert Yazıcı
Mert Yazıcı - avatar
0
Bennet Post Thank you for the help, but I was looking for a solution that does not use another variable. Thank you for your time, I really apreciate it.
26th Nov 2018, 12:47 PM
Stefan Secrieru
Stefan Secrieru - avatar
0
Mert Yazici Thank you very much, it is working. I appreaciate your time.
26th Nov 2018, 12:47 PM
Stefan Secrieru
Stefan Secrieru - avatar
0
Prokopios Poulimenos Thank you very much, it is working. It is a bit hard to understand , but I will do my best to not memorize it but to understand it. I appreaciate the help.
26th Nov 2018, 12:49 PM
Stefan Secrieru
Stefan Secrieru - avatar