The least common multiple (1cm) of two positive integers u and v is the smallest positive integer that is evenly divisible by both u and v. Thus, the 1cm of 15 and 10, written lcm (15, 10), is 30 because 30 is the smallest integer divisible by both 15 and 10. Write a function 1 that takes two integer arguments and returns their 1cm. The 1 function should calculate the least common multiple by calling the g function from
lcm (u, v) = uv / gcd (u, v) u, v >= 0
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Programming in C
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
C Programming Language
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Computer Science: An Overview (12th Edition)
Software Engineering (10th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- (Numerical) Heron’s formula for the area, A, of a triangle with sides of length a, b, and c is A=s(sa)(sb)(sc) where s=(a+b+c)2 Write, test, and execute a function that accepts the values of a, b, and c as parameters from a calling function, and then calculates the values of sand[s(sa)(sb)(sc)]. If this quantity is positive, the function calculates A. If the quantity is negative, a, b, and c do not form a triangle, and the function should set A=1. The value of A should be returned by the function.arrow_forward(Numerical) a. The following is an extremely useful programming algorithm for rounding a real number to n decimal places: Step 1: Multiply the number by 10n Step 2: Add 0.5 Step 3: Delete the fractional part of the result Step 4: Divide by 10n For example, using this algorithm to round the number 78.374625 to three decimal places yields: Step1:78.374625103=78374.625 Step2:78374.625+0.5=78375.125 Step3:Retainingtheintegerpart=78375Step4:78375dividedby103=78.375 Using this algorithm, write a C++ function that accepts a user-entered value and returns the result rounded to two decimal places. b. Enter, compile, and run the program written for Exercise 11a.arrow_forward(Statics) A beam’s second moment of inertia, also known as its area moment of inertia, is used to determine its resistance to bending and deflection. For a rectangular beam (see Figure 6.6), the second moment of inertia is given by this formula: Ibh3/12 I is the second moment of inertia (m4). b is the base (m). h is the height (m). a. Using this formula, write a function called beamMoment() that accepts two double- precision numbers as parameters (one for the base and one for the height), calculates the corresponding second moment of inertia, and displays the result. b. Include the function written in Exercise 4a in a working program. Make sure your function is called from main(). Test the function by passing various data to it.arrow_forward
- Age information for 100 families of 4 people is defined as members of a community. For every family, Send the age of each family member to a function called average (), where the average is after calculating, send the address of the average information to the main() function, main the function prints, Send the addresses of parents ' age information to function1 (), in the function, it checks whether the ages of the mother and father are double, and each if the age of both is even, it returns a value of 1 from the function, otherwise a value of 0,write a C program.arrow_forwardThe first and second numbers in the Fibonacci sequence are both 1. After that, each subsequent number is the sum of the two preceding numbers. The first several numbers in the sequence are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, etc. Write a function named fib that takes a positive integer parameter and returns the number at that position of the Fibonacci sequence. For example fib(1) = 1, fib(3) = 2, fib(10) = 55, etc. Your function does not need to print anything out - just return a value. For example, your function could be called like this: term = fib(17) You cannot use recursion, since we haven't covered that technique. That means that for this assignment you cannot have your function call itself. This includes indirect recursion, such as one function calling a second function that calls the first function. You must use a loop to step through the sequence - do not use the golden ratio to directly calculate the value.arrow_forward1. Fibonacci series can be created starting from 0 to the desired number. A function can be written for this operation and it can take two parameters: start and end. The default fırst parameter 0 is acceptable. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765..arrow_forward
- 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:GCD(x, 0) = x and GCD(x, y) = GCD(y, x % y). Examples: GCD(6, 4) -> 2 public int GCD(int x, int y) { if <<Missing base case condition>> { <<Missing base case action>> } else { return GCD(y, x % y); }}arrow_forwardIn [*]: In [ ]: In [ ]: Problem 5 Write a function that takes a price, adds 8% tax, and returns the total including the tax. Solving problem 4 will help with this problem, but this is a bit different from problem 4. (For example, we are creating a function not a code fragment, and we add the tax no matter what, not depending on add_tax.) To check that your function works, you'll want to call it with some different inputs and see what the results are! 1 #your solution goes here 2 3 price 5000 4 tax_amount=0.08 5 6 7 8 9 def price_with_tax (price): price return price price = price*0.08 1 #make one call to your function here 1 #make another call to your function here 2 # do both calls work correctly when you run them?arrow_forwardAn awake politician has made it a habit to make excuses by blaming other countries whenever something bad happens in his own country. He never repeats the country he targeted in his previous excuse. Whenever journalists ask for comments, the adviser writes on paper the name of a country other than the one used in the previous pretext and holds it in his hand. Write an excuse to facilitate the consultant's job, in accordance with the following main function named Summer. The function code can reply to the excuse message containing the name of that country by specifying a different country code from the given country code. (Supervisor countries has numbering from 1 to 10 countries. These are America, Japan, Spain, France, Russia, Qatar, Germany, Britain, China, Turkey. For example, France's code 4.)arrow_forward
- Write a function GCD( int A, int B ), when called from main function, returns the GCD (Greatest Common Divisor) of two numbers. Also get two numbers, X and Y from user and call this function to calculate GCD and show the result on Monitor. X and Y must be your reg# and 786, respectively. Note: GCD, Greatest Common Divisor: GCD of two numbers is the greatest number which can divide both the numbers. If the smaller of the two numbers can divide the larger number then the GCD is the smaller number. Else starting from 1 to (smaller / 2), check whether the current element divides both the numbers . If yes, then the highest of these devisors is the required GCD.arrow_forwardWrite a function that takes three integers namely a, b, and c as parameters. The function should return the minimum difference between any two of those. (Example: a:5 b:3 c:9 function returns 2)arrow_forwardTwo numbers are said to be co‐prime, if the greatest common divisor of the numbers is one. Forexamples,13 and 14 are co‐prime but 14 and 21 are not.a. Write a C function gcd_helper (int x, int y) to find the greatest common divisor of twonumbers x and y.b. Write a C function CoPrime_helper (int a, int b) to test whether the pair of numbers aand b are co‐prime by using gcd_helper() function.In the main() function, read five numbers and use the CoPrime_helper ( ) function to test howmany pair of them are co‐prime.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrCOMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE LC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning