1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jeka57 [31]
3 years ago
11

Write a recursive C++ function that writes the digits of a positive decimal integer in reverse order.

Computers and Technology
1 answer:
dangina [55]3 years ago
4 0

Answer:

// here is code in c++.

#include <bits/stdc++.h>

using namespace std;

// recursive function to print digit of number in revers order

void rev_dig(int num)

{

  if(num==0)

  return;

  else

   {

       cout<<num%10<<" ";

       // recursive call

       rev_dig(num/10);

   }

}

// driver  function

int main()

{

   int num;

   cout<<"enter a number:";

   // read the number from user

   cin>>num;

   cout<<"digits in revers order: ";

   // call the function with number parameter

   rev_dig(num);

   

return 0;

}

Explanation:

Read the input from user and assign it to variable "num". Call the function "rev_dig" with "num" parameter.In this function it will find the last digit as  num%10 and print it. Then call the function itself with "num/10". This will print the second last digit. Similarly it will print all the digits in revers order.

Output:

enter a number:1234                                                                                                        

digits in revers order: 4 3 2 1

Diagram :

You might be interested in
(4 points.) Write an algorithm (i.e., step-by-step instructions) via which someone could walk or drive from some origin to some
Elis [28]

Answer:

The algorithm is as follows :

1. Record Current Position, Final Destination

2. While Current Position is not Final Destination, repeat the following:

2.1 If destination location is up then:

  2.1.1 If an obstacle is directly above you then:

     2.1.1.1 Look for alternate position (left, right, down)

     2.1.1.2 If alternate position is found then

        2.1.1.2.1 Move there

        2.1.1.2.2 Record Current Position

     2.1.1.3 If no alternate position is found then

        2.1.1.3.1 Call for help

        2.1.1.3.2 End

  2.1.2 If no obstacle is directly above you then:

     2.1.2.1 Move up

     2.1.2.1 Record Current Position

2.2 If destination location is down then:

  2.2.1 If an obstacle is directly below you then:

     2.2.1.1 Look for alternate position (left, right, up)

     2.2.1.2 If alternate position is found then

        2.1.1.2.1 Move there

        2.2.1.2.2 Record Current Position

     2.2.1.3 If no alternate position is found then

        2.2.1.3.1 Call for help

        2.2.1.3.2 End

  2.2.2 If no obstacle is directly below you then:

     2.2.2.1 Move down

     2.1.2.1 Record Current Position

2.3 If destination location is right then:

  2.3.1 If an obstacle is directly by your right then:

     2.3.1.1 Look for alternate position (down, up, left)

     2.3.1.2 If alternate position is found then

        2.3.1.2.1 Move there

        2.3.1.2.2 Record Current Position

     2.3.1.3 If no alternate position is found then

        2.3.1.3.1 Call for help

        2.3.1.3.2 End

  2.3.2 If no obstacle is directly by your right then:

     2.3.2.1 Move right

     2.3.2.1 Record Current Position

2.4 If destination location is left then:

  2.4.1 If an obstacle is directly by your left then:

     2.4.1.1 Look for alternate position (down, up, right)

     2.4.1.2 If alternate position is found then

        2.4.1.2.1 Move there

        2.4.1.2.2 Record Current Position

     2.4.1.3 If no alternate position is found then

        2.4.1.3.1 Call for help

        2.4.1.3.2 End

  2.4.2 If no obstacle is directly by your left then:

     2.4.2.1 Move left

     2.4.2.1 Record Current Position

Explanation:

<em>The algorithm is straight forward.</em>

<em>All it does is to check for available position and move into the position if there is any available.</em>

<em>It keeps checking and moving until an obstacle prevents it from moving.</em>

5 0
2 years ago
Hi guy how do i make money in app cuz im desperate for 1 right now​
Margarita [4]

Answer:

we need context

Explanation:

7 0
2 years ago
Read 2 more answers
Which of the following statements is/are true? (Points : 5) A. A default constructor is automatically created for you if you do
snow_lady [41]

Answer: Only A and C

Explanation: Default constructor is a constructor that has parameters with the values that are default or has no arguments/parameter present. Default constructor is not declared in the class rather it gets generated by itself when not defined.

Class is defined with data members, functions, objects etc are considered as per the requirement given by the user .It is the user defined concept.

Statement (B) is incorrect because static method is used for accessing the static members of the particular class and manipulate the value of it.

Thus, only statement (A) and (C) are correct.

6 0
3 years ago
A mobile device user is having problems launching apps and texting. The user touches an app to launch it, but the app icon next
dalvyx [7]

Answer:

The screen protector may be interfering with the touch response

Explanation:

Screen protectors or commonly called screen guards are used to protect phone screens. In case they fall to the ground, these protectors act as shields to keep the phone screen from getting damaged. However screen protectors if not positioned or fixed properly may also cause hindrance to effective touch response as they become barriers to the touch screen.

8 0
2 years ago
A ____ error occurs when the javascript interpreter encounters a problem while a program is executing.
Leya [2.2K]
It is a runtime error thart occurs when <span>the javascript interpreter encounters a problem while a program is executing.</span>

5 0
3 years ago
Other questions:
  • Which option should you select to ignore all tracked changes in a document
    6·1 answer
  • To begin importing data from an excel spreadsheet, click on the ____ tab on the ribbon.
    11·1 answer
  • Cloud kicks recently completed the implementation of sales cloud. Cloud kicks has trained the users to use the mobile app to acc
    12·1 answer
  • Hi, please help me complete my Database Development 2 hw by completing what should been done from the document and show the code
    11·1 answer
  • Cine stie repede va rog mult si repede
    9·1 answer
  • Who Has any idea How to code?
    7·2 answers
  • I'm getting pretty desperate plz help me, I'll give brainiest, and ill make a free question worth 100 points this is for coding
    10·1 answer
  • Data type can only be true or false <br><br> Answer: Bool
    15·1 answer
  • If a system contains 1,000 disk drives, each of which has a 750,000- hour MTBF, which of the following best describes how often
    15·1 answer
  • HELP ME ⚠️‼️⚠️‼️ DUE IN EXACTLY 27 MINUTES
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!