C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5, Problem 5.39E
Program Plan Intro
- Include the header files and initialize the main() function.
- Take the input of two numbers through the user.
- Declare the function prototypes for finding gcd of the two numbers.
- Call the function to display the output.
- Define the functional role in the respective function definition.
Program description:
The program defines a function gcd that takes two integer arguments and uses this function to calculate gcd of two integers.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Objective: Practice writing recursive functions in python3
Make the five recursive functions described below in python3 by using the starter code recursive_functions.py. For each function, figure out how to solve it conceptually : write down the base case (when recursion stops) and how each recursive function-call moves towards the base case. The functions should not print anything (except you may add temporary print statements to help debug them).
You can test your program by using the provided program test_recursive_functions.py. Don't edit the test program. Put it into the same directory (folder) with your recursive_functions.py and run it. It will import your functions as a module, test your functions, and tell you when each function is returning correct results.
1. Factorial In math, if you have a number n, the factorial function (written n!) computes
n x (n-1) x (n-2) x (n-3) x ... x 1. For example:
0! is defined to be 1
1! = 1
2! = 2 x 1=2
3! = 3 x 2 x 1=6
4! = 4 x 3…
Q29
CodeW X
bFor fun X C Solved x b Answer
+ x
https://codeworko...
CodeWorkout
X265: Recursion Programmlng Exercise:
GCD
The greatest common divisor (GCD) for a pair of numbers is the largest positive integer that
divides both numbers without remainder. For function GCD , write the missing base case
condition and action. This function will compute the greatest common divisor of x and y.You
can assume that x and y are both positive integers and that x > y. Greatest common divisor
is computed as follows:
= x and GCD(x, y) = GCD(y, x % y).
Examples:
GCD (6, 4) -> 2
Your An swer:
1 public int GCD(int x, int y) {
if > {
2.
>
3.
} else {
4.
return GCD(y, x % y);
9.
{
7.
1:09 AM
50°F Clear
1V 1.
12/4/2021
甲
Chapter 5 Solutions
C How to Program (8th Edition)
Ch. 5 - Show the value of x after each of the following...Ch. 5 - (Parking Charges) A parking garage charges a $2.00...Ch. 5 - (Rounding Numbers) An application of function...Ch. 5 - (Rounding Numbers) Function floor may be used to...Ch. 5 - Write statements that assign random integers to...Ch. 5 - For each of the following sets of integers, write...Ch. 5 - (Hypotenuse Calculations) Define a function called...Ch. 5 - (Exponentiation) Write a function...Ch. 5 - Prob. 5.17ECh. 5 - Prob. 5.18E
Ch. 5 - Prob. 5.19ECh. 5 - (Displaying a Square of Any Character) Modify the...Ch. 5 - Prob. 5.21ECh. 5 - (Separating Digits) Write program segments that...Ch. 5 - (Time in Seconds) Write a function that takes the...Ch. 5 - (Temperature Conversions) Implement the following...Ch. 5 - (Find the Minimum) Write a function that returns...Ch. 5 - (Perfect Numbers) An integer number is said to be...Ch. 5 - Prob. 5.27ECh. 5 - (Reversing Digits) Write a function that takes an...Ch. 5 - (Greatest Common Divisor) The greatest common...Ch. 5 - (Quality Points for Students Grades) Write a...Ch. 5 - (Coin Tossing) Write a program that simulates coin...Ch. 5 - (Guess the Number) Write a C program that plays...Ch. 5 - (Guess the Number Modification) Modify the program...Ch. 5 - (Recursive Exponentiation) Write a recursive...Ch. 5 - (Fibonacci) The Fibonacci series 0, 1, 1, 2, 3, 5,...Ch. 5 - (Towers of Hanoi) Every budding computer scientist...Ch. 5 - Prob. 5.37ECh. 5 - Prob. 5.38ECh. 5 - Prob. 5.39ECh. 5 - Prob. 5.40ECh. 5 - (Distance Between Points) Write a function...Ch. 5 - Prob. 5.42ECh. 5 - Prob. 5.43ECh. 5 - After you determine what the program of Exercise...Ch. 5 - (Testing Math Library Functions) Write a program...Ch. 5 - Find the error in each of the following program...Ch. 5 - Prob. 5.47ECh. 5 - (Research Project: 1m proving the Recursive...Ch. 5 - (Global Warming Facts Quiz) The controversial...Ch. 5 - Prob. 5.50MDCh. 5 - Prob. 5.51MDCh. 5 - (Computer-Assisted Instruction: Monitoring Student...Ch. 5 - (Computer-Assisted Instruction: Difficulty Levels)...Ch. 5 - (Computer-Assisted Instruction: Varying the Types...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Question 2: Implementing a Recursive Function .Write recursive function, recursionprob(n), which takes a positive number as its argument and returns the output as shown below. The solution should clearly write the steps as shown in an example in slide number 59 and slide number 60 in lecture slides. After writing the steps, trace the function for “recursiveprob(5)” as shown in an example slide number 61. Function Output: >> recursionprob(1) 1 >> recursionprob(2) 1 4 >> recursionprob(3) 1 4 9 >>recrusionprob(4) 1 4 9 16arrow_forwardMULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS Use #include<stdio.h> Implement the picture shown below.arrow_forwardC programmingarrow_forward
- 3. You are expected to write a recursive function called powy(base, exponent) that, when called, returns baseponent As an example, powy( 6, 5 ) =6*6*6*6*6. Assume that exponent is an integer greater than or equal to 1. Hint: The recursion step would use the relationship baseponent - base baseponent - 1 and the terminating condition occurs when exponent is equal to 1, because base' = basearrow_forwardFrom book C How to Programarrow_forwardlanguage: Python Problem: Write a recursive function reverse(sentence) for reversing a sentence. For example, reverse('Who let the dogs out?') will return '?tuo sgod eht tel ohW'. Also write a test case in the program to prove the function given works.arrow_forward
- Please can be handwritten. Question 2: Implementing a Recursive Function . Write recursive function, recursionprob(n), which takes a positive number as its argument and returns the output as shown below. The solution should clearly write the steps as shown in an example in slide number 59 and slide number 60 in lecture slides. After writing the steps, trace the function for “recursiveprob(5)” as shown in an example slide number 61. Function Output: >> recursionprob(1) 1 >> recursionprob(2) 1 4 >> recursionprob(3) 1 4 9 >>recrusionprob(4) 1 4 9 16arrow_forwardWrite a recursive function that computes the sum of the digits in an integer. Use the following function header: def sumDigits(n):For example, sumDigits(234) returns Write a test program that prompts the user to enter an integer and displays its sum.arrow_forward2. You are expected to write a recursive function called powy(base, exponent) that, when called, returns baseexponent As an example, powy( 6, 5 ) =6*6*6*6*6. Assume that exponent is an integer greater than or equal to 1. Hint: The recursion step would use the relationship baseexponent = base basexponent - 1 and the terminating condition occurs when exponent is equal to 1, because base' = basearrow_forward
- Problem: Recursive Power Method Design a python function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised, and the exponent. Assume the exponent is a nonnegative integer. Write the main() function to input the required parameters as shown in thesample input/output. Sample Output:Average number of words per line: 26.0Enter a number: 2Enter a positive whole number between 1 and 100: 102.0 raised to the power of 10 is 1,024.00arrow_forwardFor any part that requires recursion, if you do not create a recursive function, that will result in a on that part.arrow_forwardProblem 1: Recursion to Generator You worked with these last homework. For this homework, you'll write the tail recursion, while, and generator. This is a reminder that in the starter code, we are providing you with the regular recursion code, and the functions you must implement must utilize tail recursion, a while loop, or a generator as specified. In your starter code, function names will end in _t, _w, or _g if the function needs to be implemented using tail recursion, a while loop, or a generator, respectively. Review the lecture slides to learn more about generators. p(0) p(n) = 10000 = p(n-1) + 0.02p(n − 1) c(1) = 9 c(n) = 9c(n-1) + 10-1 — c(n − 1) d(0) = 1 d(n) = 3d(n-1) + 1 Programming Problem 1: Recursion to Generators • For reach function you'll write the tail recursive form, while, and generator. • We have added the signature to help you-in particular, c(n) requres two accumula- tors. (1) (2) (3) (4) (5) (6) (7)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning