Question

Write in a c++ recursion function to prints the digits in reverse order using a recursion...

Write in a c++ recursion function to prints the digits in reverse order using a recursion function. Input: 23567 Output: 76532

Homework Answers

Answer #1

Answer:

Here is the c++ code as per your requirement

Raw code:

//header

#include <iostream>

//namespace standard

using namespace std;

//functin declaration

int reverseDigits(int num);

int main() {

//declaring variables

int num,reverse_number;

//get input from user

cin>>num;

//calling the function

reverse_number=reverseDigits(num);

//print the reversed number.

cout<<reverse_number<<endl;

}

//declaring variables

int sum=0,rem;

//function declaration

int reverseDigits(int num){

//positive number

if(num){

//get the remainder of it

rem=num%10;

sum=sum*10+rem;

//get the remaining sum

//send the remaining digts to recusrsive function

reverseDigits(num/10);

}

//else return sum as 0

else{

return sum;

}

return sum;

}

Editor:

output:

Hope this helps you! If you still have any doubts or queries please feel free to comment in the comment section.

"Please refer to the screenshot of the code to understand the indentation of the code".

Thank you! Do upvote.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ Using recursion write a program that takes a positive integer number and returns whether...
In C++ Using recursion write a program that takes a positive integer number and returns whether there is 6. For example, if the input number is 7068, the function returns true
(USING ML) (Using ML) Write a function dupList of type 'a list -> 'a list whose...
(USING ML) (Using ML) Write a function dupList of type 'a list -> 'a list whose output list is the same as the input list but with each element of the input list repeated twice in a row. For example, if the input is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If the input list [], the output list should be []. Do not use explicit recursion but use one of the fold...
PLEASE HURRY, will upvote if correct python Write a method that prints characters using the following...
PLEASE HURRY, will upvote if correct python Write a method that prints characters using the following header: def printChars(ch1,ch2): this function prints out the characters between ch1 and ch2 inclusive. Assumption is that ch2 is always bigger than c1 and both lower cases. also Write a function that accepts a list as an argument and prints the number of occurrence of each item def itemOccurence(myList): i.e. input ("Hello",123, 342, 123, "Hello",123) output: 2 times "Hello" 3 times 123 1 time...
IN C++ VERY EASY What's wrong with this code? The following function prints a reverse half-pyramid...
IN C++ VERY EASY What's wrong with this code? The following function prints a reverse half-pyramid populated by the alternating dots and stars (see example below). The odd rows contain stars and even rows contain dots. Debug the code to fix all the compilation and run-time errors, so that the code generates the desired output. For instance, when the 'n' value passed to the function is 6, the output would look like the following. ****** ..... **** ... ** ....
Write a program in C that uses recursion to calculate and print the factorial of the...
Write a program in C that uses recursion to calculate and print the factorial of the positive integer value passed in or prints the line "Huh?" if no argument is passed or if the first argument passed is not a positive integer. If the value passed in exceeds 10, you can simply print "Overvalue".
Write a Python program using that takes a number as input and then prints if the...
Write a Python program using that takes a number as input and then prints if the number is even or odd. The program should use a function isEven that takes a number as a parameter and returns a logical value true if the number is even, false otherwise.
In C programming language write a function that takes an integer n as input and prints...
In C programming language write a function that takes an integer n as input and prints the following pattern on the screen: 1 (n times) 2 (n-1 times) .n (1 time) For example, if n was 5, the function should print 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
Write a program that reads a word and then prints the word in reverse separated by...
Write a program that reads a word and then prints the word in reverse separated by a comma. 3 pts Note: No comma at the end of the reversed word. Enter word: Harry The reversed word is: y,r,r,a,H Python keep it simple
**C code only In this part, you will write a simple user-defined function that prints a...
**C code only In this part, you will write a simple user-defined function that prints a message. This function does not require any parameters or return value. The purpose is simply to get you started writing functions.Open repl project Lab: User-Defined Functions 1. Write a program that calls a function. This function should do the following: 1.Ask the user their name 2. Print a "hello" message that includes the user's name Example output: Please enter your name: ​Mat Hello, Mat!...
How do you write a python function that prints numbers contained within a range of numbers...
How do you write a python function that prints numbers contained within a range of numbers ( for example 300 to 400) and the numbers printed by the function are self-divisible by all digits in the number. Could you assist?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT