MYPROGRAMMINGLAB WITH PEARSON ETEXT
8th Edition
ISBN: 9780134225340
Author: Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5, Problem 5.39E
Program Plan Intro
Program Plan-
- 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
(Recursive Greatest Common Divisor) The greatest common divisor of integers x and y isthe largest integer that evenly divides both x and y. Write a recursive function gcd that returns thegreatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equalto 0, then gcd(x, y) is x; otherwise gcd(x, y) is gcd(y, x % y), where % is the remainder operator.
6. Write a recursive function that find the sum of the following series.
1+1/2+1/4+1/8+...+1/2"
(C Language) Write a recursive function called DigitCount() that takes a non-negative integer as a parameter and returns the number of digits in the integer. Hint: The digit count increases by 1 whenever the input number is divided by 10.
Chapter 5 Solutions
MYPROGRAMMINGLAB WITH PEARSON ETEXT
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
- Exponent y Catherine Arellano mplement a recursive function that returns he exponent given the base and the result. for example, if the base is 2 and the result is 3, then the output should be 3 because the exponent needed for 2 to become 8 is 3 (i.e. 23 = 8) nstructions: 1. In the code editor, you are provided with a main() function that asks the user for two integer inputs: 1. The first integer is the base 2. The second integer is the result 2. Furthermore, you are provided with the getExponent() function. The details of this function are the following: 1. Return type - int 2. Name - getExponent 3. Parameters 1. int - base 2. int - result 4. Description - this recursive function returns the exponent 5. Your task is to add the base case and the general case so it will work Score: 0/5 Overview 1080 main.c exponent.h 1 #include 2 #include "exponent.h" 3 int main(void) { 4 int base, result; 5 6 printf("Enter the base: "); scanf("%d", &base); 7 8 9 printf("Enter the result: ");…arrow_forwardI just need the if statement to the code to execute.arrow_forward3. Observe the following formulae: fin) = 1 fin) = 3 + f(n-1) fin) = 2 + f(n-1) if n=0 if n is even if n is odd a) Write a direct recursive function based on the formulae above. The function prototype is given as: int f(int n); Note: You don't have to worry about n being less than 0, but beware of 0 being an even number. b) Using mutual recursion and based on the formulae above, complete the function definition for the following function prototypes: int fodd (int n) ; int fEven (int n); c) Write a complete C program to test the direct and mutual recursions that you have written in Parts (a) and (b). Prompt the user for n values.arrow_forward
- Consider the following function shoots : def shoots(x: int) -> int: if x <= 0: return 0 4 elif x == 1: return shoots(x + 2) 6 elif x == 2: return shoots(x - 1) 80 elif x == 2: 9. return -1 10 else: 11 return shoots(x - 2) 2 3arrow_forwardWhich of the following statements are true?■ Any recursive function can be converted into a nonrecursive function.■ Recursive functions take more time and memory to execute than nonrecursive functions.■ Recursive functions are always simpler than nonrecursive functions.■ There is always a selection statement in a recursive function to check whether a base case is reached.arrow_forwardMULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS Use #include<stdio.h> Write a function main() and implement each math operations defined above. Design a basic calculator that will asks from the user to enter 2 integers and the math operator symbol as shown below: (the highlited part)arrow_forward
- 2, Towers of Hanoi Problem. (10 points) The Towers of Hanoi is a famous problem for studying recursion in computer science and searching in artificial intelligence. We start with N discs of varying sizes on a peg (stacked in order according to size), and two empty pegs. We are allowed to move a disc from one peg to another, but we are never allowed to move a larger disc on top of a smaller disc. The goal is to move all the discs to the rightmost peg (see figure). To solve the problem by using search methods, we need first formulate the problem. Supposing there are K pegs and N disk. Answer the following questions. (1) Determine a state representation for this problem. (4points) (2) What is the size of the state space? (3 points) (3) Supposing K=3, N=4, what is the start state by using your proposed state representation method and what is the goal state? (3 points)arrow_forwardPlease use easy logic with proper indentations and comments for understanding!. Coding should be in C++. 1. Write a recursive function named printStars which receives an int parameter. If the parameter is positive, the function prints the given number of asterisks; otherwise the function does nothing. The function does not return a value. Thus, if the printStars(8) is called, ******** (8 asterisks) will be printed. The function must not use a loop of any kind to accomplish its job. Instead, it gets the job done by (recursively) calling itself.arrow_forwardN.B: Use all the recursive functions in one C++ code 1. Write a recursive function that returns the nth Fibonacci number from the Fibonacci series. int fib(int n); 2. Write a recursive function to find the factorial of a number. int factorial(int n); 3. Write a recursive function that returns the sum of the digits of an integer. int sumOfDigits(int x); 4. Write a recursive function that find the minimum element in an array of integers. int findMin(int a[], int size); 5. Write a recursive function that converts a decimal number to binary number. int DecToBin(int dec); 6. Write a recursive function that find the sum of the following series. 1 + 1/2 + 1/4 + 1/8 + ... + 1/2narrow_forward
- C Program: An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. I have written a function called isPerfect (see below), that determines whether parameter passed to the function is a perfect number. Use this function in a C program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect. // isPerfect returns true if value is perfect integer, // i.e., if value is equal to sum of its factors int isPerfect(int value) { int factorSum = 1; // current sum of factors // loop through possible factor values for (int i = 2; i <= value / 2; ++i) { // if i is factor if (value % i == 0) { factorSum += i; // add to sum } } // return true if value is equal to sum of factors if (factorSum == value) { return…arrow_forwardQ1: Write a program using function with Return Type and with Parameter to print out all Palindrome numbers between 501 and 550. Q2: A 5-digit positive integer is entered through the keyboard, write a function to calculate multiplication of digits of the 5-digit number: (1) Without using recursion (2) Using recursion Q3: To fully define a variable one needs to mention not only its 'type' but also its 'other properties'. In other words, not only do all variables have a data type, they also contain other properties. Explain the concept that will help us to describe the properties of any variable. Q4: Write a short note on Array.arrow_forwardFind any errors in the following function definition: void fun (int, x) { return; } // funarrow_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