Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
John Regard
Greenhorn
+ Follow
news
1
Posts
0
Threads
since Feb 01, 2023
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads
Recent posts by John Regard
I want C program that receives numbers until the user input (-1), then print reverse all of numbers
first, take out the while loop from the recursive function and put it on the main function instead.
then, your prorgam function should look something like
// iterative version int rev_num = 0; while(n){ rev_num = rev_num * 10 + n % 10; n /= 10; } // recursive version int reverse(int n, int rev_num=0){ if (n == 0) return rev_num; return reverse(n / 10, rev_num * 10 + n % 10); }
show more
2 years ago
C / C++