Question

16. Here below is the skeleton of the function for reversing digits. Finish the function definition. (10 pts) int reversDigits (int num) int rev-num = 0; //the reversed digits While Cnum >10 ) 2 17. Rewrite the above function applying recursive function (10 pts)
media%2F9d5%2F9d5c5c52-5953-4a66-81e3-05
0 0
Add a comment Improve this question Transcribed image text
Answer #1

int sum=0,rem;
rev_fn(int num){
   if(num){                   //if number is not zero then it is true
      rem=num%10;             //claculate reminder
      sum=sum*10+rem;         //sum will store the reverse number atlast
      rev_fn(num/10);        //recursive function
   }
   else
      return sum;            //when num becomes zero return sum
   return sum;
}

Program and OUTPUT:

Explanation:

Add a comment
Know the answer?
Add Answer to:
16. Here below is the skeleton of the function for reversing digits. Finish the function definition....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Consider the following recursive function (Chapter 17, #9, modified) void recFun (int x) { if...

    2. Consider the following recursive function (Chapter 17, #9, modified) void recFun (int x) { if (x > 10) { recFun (x / 10); cout<< X % 10; } else cout<< x; } a) What is printed by the call: recFun (268); b) How can the code be modified so that when a number is input, its digits are printed on separate lines? c) How can the code be modified so that the sum of all digits is printed?

  • Write a python program write a function numDigits(num) which counts the digits in int num. Answer...

    Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...

  • Solve the Consumer/Producer problem using semaphores. A skeleton program (Save it as producer_consumer.c) is provided to...

    Solve the Consumer/Producer problem using semaphores. A skeleton program (Save it as producer_consumer.c) is provided to you: The main function creates 2 threads: consumer represents the consumer and executes the consume function, and producer represents the producer and executes the  produce function. You should declare and initialize 3 semaphores. Those semaphores should be used in the consume(..) and produce(...) functions. #include <stdio.h> #include <stdlib.h> #include <pthread.h> //compile and link with -pthread #define BUFFER_SIZE 10 int buffer[BUFFER_SIZE]; int in, out; int num;...

  • Here is the skeleton of the password checking program. We have the character counting function (you...

    Here is the skeleton of the password checking program. We have the character counting function (you will need to finish it), and a function to check if the password is good. Change the password algorithm so that (three of the four) two uppercase, two lowercase, two digits, or one other is present. Also change the required length of the password to 10. Bonus points for making the program loop until a good password is entered. You will need to read...

  • In C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

  • C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function...

    C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function prototype, function heading, function body, and function definitions. b. Function call statements, formal parameters, and actual parameters. C. Value parameters and reference parameters. d. Local variables and global variables. 6. Named constants. #include <iostream> //Line 1 using namespace std; //Line 2 const double NUM = 3.5; //Line 3 int temp; //Line 4 void func(int, doubles, char); //Line 5 int main() int num; double one;...

  • 4. Consider the following (almost) complete program: 4includeciostream> using namespace std: la)prototypes here. int main ()...

    4. Consider the following (almost) complete program: 4includeciostream> using namespace std: la)prototypes here. int main () const int size 6 int alsize] 15, 2, 3, 1, 13, 8): int p pma+1 show (a, size) mystery (a, size); show (a, aize) cout<<a [2]+a(51<<endl; cout<<(a+2)-3<<endl: cout<<tp+ a<<endl; cout<<at5<cendl void show (int all, int n) 17 (b) define show void mystery (int all, int n) int temp Eor (int i-0 i<n/2 i++) temp aij alil-aln-i-117 a [n-i-11 temp a) Write prototypes for the...

  • CHALLENGE ACTIVITY 13.1.2: Basic function call. Complete the function definition to output the hours given minutes....

    CHALLENGE ACTIVITY 13.1.2: Basic function call. Complete the function definition to output the hours given minutes. Output for sample program: 3.5 1 test passed All tests passed 1 #include <iostream> 2 using namespace std; 3 4 void OutputMinutesAsHours (double origMinutes) { 5 6 /* Your solution goes here */ 7 8} 9 10 int main() { 11 double minutes; 12 13 cin >> minutes; 14 15 OutputMinutesAsHours (minutes); // Will be run with 210.0, 3600.0, and 0.0. 16 cout <<...

  • For each of the below code snippets, identify the bounding function (the big O) of the...

    For each of the below code snippets, identify the bounding function (the big O) of the number of times the indicated line is run (justify your answer briefly): int i = 1: while (i < n) { printf ("Insert difficult work here!") i = i + i: } for(i = 0: i < n: i++) { for (j = 0: j < n: j++) { for (k = 0: k < n: k++) { if(i==j && j==k) arr[i] [j] [k]...

  • Please Answer 135 Below Completely: Definition Let E-R and f : E-+ R be a function....

    Please Answer 135 Below Completely: Definition Let E-R and f : E-+ R be a function. For some p E E' we say that f is continuous at p if for any ε > 0, there exists a δ > 0 (which depends on ε) such that for any x E E with |x-Pl < δ we have If(x) -f(p)le KE. This is often called the rigorous δ-ε definition of continuity. A couple of things to note about this definition....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT