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 the following can ensily reverse motion and are better at varying speeds than electrical motors?
harkovskaia [24]

Answer:

Where are the following? You have to post the full question if you want help.

Explanation:

7 0
3 years ago
A security engineer is configuring a wireless network that must support mutual authentication of the wireless client and the aut
rewona [7]

Answer:C) PEAP(Protected Extensible Authentication Protocol)

Explanation: PEAP(Protected Extensible Authentication Protocol) is the protocol that is used in point-to-point network connection and wireless network connection.It is the version of EAP(Extensible Authentication Protocol) with the advantage of protection to maintain the security.

Other options are incorrect because EAP-FAST is the EAP protocol with that has flexible authentication through secure tunneling, EAP-TLS is the EAP protocol with the transfer layer security and EAP is used for the expansion of authentication method for the network between internet and computer system.Thus, the correct option is option(c).

7 0
2 years ago
How do i get around goguardian from a chromebook
Dafna11 [192]

Answer:

Navigate to your GoGuardian Classroom.

Click the Students tab.

Click the X icon to the right of the student's name.

Confirm by selecting Remove Student from the popup.

Explanation:

GoGuardian Off-campus filtering. Even after class, students still need access to the best learning tools for their education. ... Using Google's Admin Console and Chrome OS, GoGuardian is able to offer its complete Chromebook filtering and monitoring software wherever the device may be.

3 0
3 years ago
Can you withdraw from courses in top hat?
ad-work [718]

Answer:

Yes, but this must be done before the withdraw deadline

Explanation:

TopHat is an online learning platform. Students register for courses and if they decide not to continue with a course for reasons best known to them, they are allowed a time period usually one to two weeks to drop the courses. They are then reimbursed the fee for that particular course.

But if that time period elapses and they drop the course, that is considered a withdrawal that is not accepted and which no provisions for reimbursements are made.

7 0
2 years ago
6. Which hypothesis about the fate of the universe says that it will expand continuously as the galaxies drift far apart and all
zaharov [31]
A. The big bang theory
6 0
3 years ago
Other questions:
  • What is UNIX? A program for writing documents Graphical interface Internet browser Operating system
    8·2 answers
  • You're trying to improve an ad's perceived quality so it performs better during an ad auction. What change would have the least-
    15·1 answer
  • ____ technology essentially takes the data to be transmitted and rather than transmitting it in a fixed bandwidth spreads it ove
    15·1 answer
  • Suppose L is a LIST and p, q, and r are positions. As a function of n, the length of list L, determine how many times the functi
    8·1 answer
  • How can you tell the value of a purchase?
    7·1 answer
  • Write a program that prompts the user to enter a number then counts the number of odd numbers and even numbers the user enter. T
    15·1 answer
  • write a pay-raise program that requests a person's first name, last name, and current annual salary, and then displays the perso
    6·1 answer
  • Write a program that takes paragraph from the user and prints all unique words in that paragraph using strings in c++
    5·1 answer
  • A human interest story is an example of hard news.<br> O True<br> O False HEL
    15·1 answer
  • Synthesize (15 points)
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!