Concept explainers
Given two integers x snf y, the following recurrsive definition determined the greatest common divisor of x and y, Write gcd(xy). Write a recursive function, gcd, that takes two integers as parameters and returns the greatest commmon divisorof numbers.Also write a program to test your function. Write a recursive function,reverseDigits, that takes an integer as a parameter snd returns the number with the digits reversed. Also write a program to test your application. (
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
need to create java guessing game. user will choose the number and say l/h/c as lower higher and correct
need to create java guessing game. user will choose the number and say l/h/c as lower higher and correct
- In Kotlin, Write and test a recursive function called harm with an expression body that takes an Int argument n and calculates the sum of 1/1 ... 1/n. For example, harm(3) should return about 1.833333333. You do not need to worry about integer division.arrow_forwardneed help Writing a recursive function, isPalindrome, to check if a string is a palindrome. Return true if the string is a palindrome; otherwise, return false. in javascript example isPalindrome('Kayak'); // => true i sPalindrome('NEVERODDOREVEN'); // => true i sPalindrome('Tacocat'); // => true isPalindrome('SELFLESS'); // => falsearrow_forwardPlease help me with these question. I am having trouble understanding what to do. Please use HTML, CSS, and JavaScript Thank youarrow_forward
- Python. Write a short recursive Python function without using any loops. that determines if a string s is a palindrome, that is, it is equal to its reverse. For example, racecar and gohangasalamiimalasagnahog are palindromes. (FYI strings are alphanumeric). (No loops)arrow_forwardWrite a function that implements the quadratic equation. Given three inputs (a, b, and c), calculate the roots (r1 (+) and r2 (-)) of the quadratic formula. Review 19 Write a function that implements the quadratic equation. Given three inputs (a, b, and c), calculate the roots (r1 and r2) of the quadratic formula. Call your function Roots a = 1 b = 2 c = -3 [r1,r2]=Roots(a,b,c)arrow_forwardCalling a recursive function. Write a statement that calls the recursive function backwards_alphabet() with input starting_letter.Sample output with input: 'f' f e d c b a def backwards_alphabet(curr_letter): if curr_letter == 'a': print(curr_letter) else: print(curr_letter) prev_letter = chr(ord(curr_letter) - 1) backwards_alphabet(prev_letter) starting_letter = input() ''' Your solution goes here '''arrow_forward
- Write a program named stars.py that has two functions for generating star polygons. One function should be implemented using an iteration (a for loop), and another function should be a recursion. It is optional to fill in your shapes. The functions for generating stars should be named star (size, n, d=2) and star_recursive (size, n, level, d=2), where size is the size of the polygon side (edge), n is the number of sides (or angles), d is a density or winding number that should be set to default value 2, and level is the level of recursion initially equal to n.arrow_forwardWrite code to complete raise_to_power(). Note: This example is for practicing recursion; a non-recursive function, or using the built-in function math.pow(), would be more common.Sample output with inputs: 4 24^2 = 16 def raise_to_power(base_val, exponent_val): if exponent_val == 0: result_val = 1 else: result_val = base_val * ''' Your solution goes here ''' return result_val user_base = int(input())user_exponent = int(input()) print('{}^{} = {}'.format(user_base, user_exponent, raise_to_power(user_base, user_exponent)))arrow_forwardWrite a program called p3.py that contains a function called reveal_recursive() that takes a word (string) and the length of the word (int) as input and has the following functionality: 1. prints the word where all characters are replaced by underscores 2. continue to print the word revealing one character at a time. i.e., the second line printed should print the first character followed by “_”’s representing the rest of the word. (see example below) 3. the function should end after printing the entire word once. 4. This function should be recursive Example: #the word is kangaroo ________ k_______ ka______ kan_____ kang____ kanga___ kangar__ kangaro_ kangarooarrow_forward
- hi. i got the answer to this question wrong despite asking one of your experts. Please can you give another go and help me by providing a detailed solution to this question. Thank youarrow_forwardWrite code to complete raise_to_power). Note: This example is for practicing recursion; a non-recursive function, or using the built-in function math.pow(0, would be more common. Sample output with inputs: 4 2 4^2 = 16 344614.2214230.qx3zqy7 1 def raise_to_power (base_val, exponent_val): if exponent_val result_val 2 0: == = 1 4 else: result_val base_val * Your solution goes here ... = 6. 7 return result_val 9 user_base 10 user_exponent int (input ()) int (input ()) = = 11 12 print ('{}^{} {}'.format (user_base, user_exponent, raise_to_power (user_base, user_exponent))) 13arrow_forwardJava, I am not displaying my results correct. It should add up the digits in the string. input string |result for the sumIt Recursion functions and a findMax function that finds the largest number in a string "1d2d3d" | 6 total "55" |10 total "xx" | 0 total "12x8" |12 Max number "012x88" |88 Max Number "012x88ttttt9xe33ppp100" |100 Max Number public class Finder { //Write two recursive functions, both of which will parse any length string that consists of digits and numbers. Both functions //should be…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education