Question

The least common multiple (lcm) of two positive integers u and v is the smallest positive...

The least common multiple (lcm) of two positive integers u and v is the smallest positive integer that is evenly divisible by both u and v. Thus, the lcm 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 lcm() that takes two integer arguments and returns their lcm. The lcm() functon should calculate the least common multiple by calling the gcd() function from program 7.6 in accordance with the following identity:

lcm (u, v) = uv / gcd (u, v)

u, v >= 0

(In C language)

hint: You will need to use the authors gcd function in an expression.

Program 7.6:

/* Function to find the greatest common divisor of two

     nonnegative integer values and to return the result    */

#include

int gcd (int u, int v)

{

            int temp;

            while (v != 0)

            {

                        temp = u % v;

                        u = v;

                        v = temp;

            }

            return u;

}

int main (void)

{

            int result;

            result = gcd (150, 35);

            printf ("The gcd of 150 and 35 is %i\n", result);

            result = gcd (1026, 405);

            printf ("The gcd of 1026 and 405 is %i\n", result);

            printf ("The gcd of 83 and 240 is %i\n", gcd (83, 240));

            return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
The least common multiple (lcm) of two positive integers u and v is the smallest positive...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Solve the following question using Matlab language only. Least common multiple (LCM) of two numbers is...

    Solve the following question using Matlab language only. Least common multiple (LCM) of two numbers is the smallest number that they both divide. For example, the LCM of 2 and 3 is 6, as both numbers can evenly divide the number 6. Find the LCM of two numbers using recursion Hint: You may assume that the first number is always smaller than the second number. Examplel First number for LCM:3 Second number for LCM 19 The LCM of 3 and...

  • PYTHON In mathematics, the Greatest Common Divisor (GCD) of two integers is the largest positive integer...

    PYTHON In mathematics, the Greatest Common Divisor (GCD) of two integers is the largest positive integer that divides the two numbers without a remainder. For example, the GCD of 8 and 12 is 4. Steps to calculate the GCD of two positive integers a,b using the Binary method is given below: Input: a, b integers If a<=0 or b<=0, then Return 0 Else, d = 0 while a and b are both even do a = a/2 b = b/2...

  • 1) Given two positive numbers, write a program using while loop to determine their lowest common...

    1) Given two positive numbers, write a program using while loop to determine their lowest common multiple. You cannot use any automatic LCM, GCD finder function or return command. Program Inputs • Enter the first number: – The user can enter any positive whole number, no error checking required • Enter the second number: – The user can enter any positive whole number, no error checking required Program Outputs • The LCM of X and Y is Z! – Replace...

  • Write a program whose input is two integers and whose output is the two integers swapped....

    Write a program whose input is two integers and whose output is the two integers swapped. Write in C language 7.3 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 38 then the output is: 83 Your program must define and call a function. SwapValues returns the two values in swapped order. void SwapValues(int* userVali, int* userVal2) ACRIVITY 7.3.1: LAB: Swapping variables 0/10 ] main.c...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • Header file for the Rational class: #ifndef RATIONAL_H #define RATIONAL_H class Rational { public: Rational( int...

    Header file for the Rational class: #ifndef RATIONAL_H #define RATIONAL_H class Rational { public: Rational( int = 0, int = 1 ); // default constructor Rational addition( const Rational & ) const; // function addition Rational subtraction( const Rational & ) const; // function subtraction Rational multiplication( const Rational & ) const; // function multi. Rational division( const Rational & ) const; // function division void printRational () const; // print rational format void printRationalAsDouble() const; // print rational as...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT