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!
5 Antworten
+ 8
return (n%10)*pow(10, (int)log10(n)) + oglindit(n/10);
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.
0
Mert Yazici
Thank you very much, it is working. I appreaciate your time.
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.