Q1. that returns the smallest common multiple of two given positive integers.For example, the smallest common multiple of integer 2 and 5 is 10; the smallest common multiple of integer 20 and 12 is 60; the smallest common multiple of integer 8 and 4 is 8.
Q2. The Babylonian algorithm to compute the square root of a positive number num is as follows:1. Make a guess at the answer (you may pick num/2 as your initial guess)2. Compute div = num / guess3. Set guess = (guess + div) / 24. Go back to step 2 for as many iterations as necessary. The more step 2 and 3 are repeated, the closer guess will become to the square root of num.Implement this algorithm in a function named squareRoot that takes a positive number of type double as its argument and iterates through the Babylonian algorithm until the change of the guesses is within 1% of the previous guess. The function should return the square root as a double.
Q3. This question is about Fibonacci number. For your information, the Fibonacci sequence is as follows:0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, That is, the first two Fibonacci numbers are 0 and 1, each Fibonacci number after that is equal to the sum of the two numbers that precede it. For example, the third Fibonacci number is equal to the sum of the first and second number,the fourth number is equal to the sum of the second and third number, and so on Define a function named isFibNum that takes a non-negative integer as its argument and checks (returns true or false) whether the argument is a Fibonacci number. Note: you should not use array for this question.
5/5 – (3 votes)
Reviews
There are no reviews yet.