1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
il63 [147K]
2 years ago
9

Write a program with 2 separate functions which compute the GCD (Greatest Common Denominator) and the LCM (Lowest Common Multipl

e) of two input integers.
Computers and Technology
1 answer:
Maru [420]2 years ago
5 0

Answer:

The program written in Python is as follows

def GCD(num1, num2):

    small = num1

    if num1 > num2:

         small = num2

    for i in range(1, small+1):

         if((num1 % i == 0) and (num2 % i == 0)):

              gcd = i

    print("The GCD is "+ str(gcd))

def LCM(num1,num2):

    big = num2  

    if num1 > num2:

         big = num1

    while(True):

         if((big % num1 == 0) and (big % num2 == 0)):

              lcm = big

              break

         big = big+1

     print("The LCM is "+ str(lcm))

 print("Enter two numbers: ")

num1 = int(input(": "))

num2 = int(input(": "))

GCD(num1, num2)

LCM(num1, num2)

Explanation:

This line defines the GCD function

def GCD(num1, num2):

This line initializes variable small to num1

    small = num1

This line checks if num2 is less than num1, if yes: num2 is assigned to variable small

<em>     if num1 > num2: </em>

<em>          small = num2 </em>

The following iteration determines the GCD of num1 and num2

<em>     for i in range(1, small+1): </em>

<em>          if((num1 % i == 0) and (num2 % i == 0)): </em>

<em>               gcd = i </em>

This line prints the GCD

    print("The GCD is "+ str(gcd))

   

This line defines the LCM function

def LCM(num1,num2):

This line initializes variable big to num2

    big = num2  

This line checks if num1 is greater than num2, if yes: num1 is assigned to variable big

<em>     if num1 > num2: </em>

<em>          big = num1 </em>

The following iteration continues while the LCM has not been gotten.

    while(True):

This if statement determines the LCM using modulo operator

<em>          if((big % num1 == 0) and (big % num2 == 0)): </em>

<em>               lcm = big </em>

<em>               break </em>

<em>          big = big+1 </em>

This line prints the LCM of the two numbers

     print("The LCM is "+ str(lcm))

The main starts here

This line prompts user for two numbers

print("Enter two numbers: ")

The next two lines get user inputs

num1 = int(input(": "))

num2 = int(input(": "))

This calls the GCD function

GCD(num1, num2)

This calls the LCM function

LCM(num1, num2)

<em></em>

<em>See attachment for more structured program</em>

Download txt
You might be interested in
Icon view, list view, and details view are all common views provided by which kind of program?
RideAnS [48]
The standard program that uses common views such as the icon view, list view, and details view would be the program known as "File Explorer" (Windows) or "Finder" (Mac). This program uses all the views to make selecting and tracking down certain files a much more painless and easier process to complete.

Hope this helps and good luck! :)
6 0
3 years ago
Read 2 more answers
On a client/server network, which computer initiates the process of assigning an IP address through DHCP?
Vera_Pavlovna [14]

Answer:

The client

Explanation:

On a client/server network, THE CLIENT computer initiates the process of assigning an IP address through DHCP. This is because "The Client" computer will serve as the Domain controller in which other computers of the network can find. Hence, The Client computer initiates the process of assigning IP addresses through DHCP to achieve this.

Though, in some case. A user can manually assign the IP address to computer if it is not through DHCP

4 0
3 years ago
What is the other name designated to a game master of multiplayer online games (MMOs)?
kari74 [83]

Answer: b. expert

Explanation: generally game masters have more experience than most other players and help moderate the game.

6 0
3 years ago
Read 2 more answers
In a submarine battle simulation, you know all the locations the enemy units can move to. Anticipating these moves, you call for
BaLLatris [955]

Answer:

perfect information

Explanation:

7 0
3 years ago
Read 2 more answers
A person whose body can still function properly without the drug but still craves the drug even though the high is not as intens
KIM [24]
Hello there!

You’re answer may be - Addicted.

Even though the persons body can function properly without the drug, they can still be considered addicted. Drug addictions tend to accur after long uses of drugs, which may be legal... or illegal.

I hope this helps you! Feel free to ask me for help anytime!

~Alexa
8 0
2 years ago
Other questions:
  • Laurence Sims owns a football team that plays its home games in City Stadium. To increase revenue, he is offering a sponsorship
    14·1 answer
  • For a loop counter, the appropriate data type would be:
    14·1 answer
  • Which option is used to apply formatting to multiple objects on a single slide while still maintaining the ability to manage the
    14·2 answers
  • ____ are programs that need to be attached to other files to install themselves on computers without the users’ knowledge or per
    5·1 answer
  • Benjamin recently issued new mobile phones to the marketing team at his company. Each phone can transmit encrypted information f
    8·1 answer
  • NEED BY 15 MINUTES PLEASE! WILL MARK BRAINLIEST!You can create special effects in an image using a camera or a photo-editing too
    5·1 answer
  • 3.19 LAB: Seasons In C++ Write a program that takes a date as input and outputs the date's season. The input is a string to repr
    15·1 answer
  • Why would a user want to resend a message? Check all that apply.
    7·2 answers
  • Which of the following is not a bus type A. Address bus B. Data bus C. Memory bus D. Control bus ​
    7·2 answers
  • The ACME Online Store offers different preferred customer discounts for customers who are "None", "Bronze", "Silver" and "Gold".
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!