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]
3 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]3 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
Which of these is NOT one of the main parts of an email?
slega [8]
I think the answer is c
3 0
3 years ago
Read 2 more answers
Derive an expression for the boolean function L(a,c) whose output is 1 when the light would be on. Note that two of the switches
Naddik [55]

Answer:

Following are the solution to the given question:

Explanation:

Please find the graph image in the attachment file.

In the sequence, they recognize how modules are divided and elements were introduced in parallel. L(a,c) is thus going to also be

\to a*c + a'*c' = ac + a'c'

It allows, ideally, to bring a thumbs up.

3 0
2 years ago
Linda works from home occasionally and needs to set up her computer at work so she can remote in from her home office. Which too
qwelly [4]

Explanation:

Check the type of hard drive installed.

hope this helps you ❣️

4 0
2 years ago
Explain basic anatomy of computers.
jeyben [28]

Explanation:

A computer system can be divided into two components which are responsible for providing the mechanisms to input and output data, to manipulate and process data, and to electronically control the various input, output, and their storage. ... They are known as hardware and software.

4 0
2 years ago
Read 2 more answers
Which action is applicable only to tables?
crimeas [40]

Answer:

the answer is adding and deleting rows

3 0
2 years ago
Other questions:
  • Hybrid protocol is similar to which other protocol?
    10·1 answer
  • A statement describing both the requirements that must be met by a product or process amd the ways in which satisfaction of the
    8·2 answers
  • You and your friend who lives far away want to fairly and randomly select which of the two of you will travel to the other’s hom
    6·1 answer
  • My name Jeff <br><br> what movie is this off of
    6·2 answers
  • write a c++ program that writes weather data from a file wx_data.txt to a file wx_summary for everyday of the year. also add min
    15·1 answer
  • What do you consider to be the next big thing in "Small Systems" (technology, hardware, software, etc.) and why?
    10·1 answer
  • Direction: using the data at the left, answer the questions that follows.​
    11·1 answer
  • If a friend gave a used Wii disc to someone, and they put it in their Wii, could they play it? Nintendo Switch games can only be
    14·1 answer
  • Why is it important to prepare the farm resources before you start working? explain​
    14·1 answer
  • IM a bit confused on what this is asking for exactly.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!