Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help me , I am stuck in in part B , I finished part A but I am unsure as to how to do

image text in transcribed

please help me , I am stuck in in part B , I finished part A but I am unsure as to how to do part B , we have to use recursion in C programming

A. Now that we know loops, we can write a function that converts a number's represen- tation between two bases. Numbers are internally represented in base 2, but when you print an integer x with printf("%d ", x); you get the decimal representation of the number. For this problem, you write a function that mimics the conversion that printf performs when it prints in decimal format. (You still use printf to print each digit.) The function prototype is int printDecimalDigits (int n)i If a number less than or equal to 0 is passed as input, the function should print nothing and return -1. Otherwise, it should print each decimal digit of n on a separate line starting from the least significant one (units first, followed by tens, and so on). The function should then return 0. No leading zeros should be printed. Use a while loop to implement your function and write a unit test that adequately exercises it. B. Continuing Problem A, now write a function that prints the decimal digits of its argu- ment starting from the most significant one. Keep the same interface and unit test as in Problem A. Use recursion to solve this problem. Note how recursion allows you to print the digits in reverse order of computation. If we want to use a loop instead of recursion, we need to wait until Chapter 3 to achieve the same resu

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Identify the motives that fuel prejudice.

Answered: 1 week ago