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
3 component of a computer
madam [21]

Answer:

Hardware

software

Humanware

6 0
3 years ago
In an all-integer linear program,
xenn [34]

Answer: E

All decision variables must be integer

Explanation:

The integer-linear program is a program in which the objective function and any constraints are all linear ie all of the variables are restricted to be integers.

A linear program is Np complete. Also every decision variable appear in any constraints must also appear in the objective function, possibly with zero coefficient if needed.

8 0
3 years ago
(1) Output a menu of automotive services and the corresponding cost of each service. (2 pts) Ex: Davy's auto shop services Oil c
Wittaler [7]

Answer:

service1_cost = 0

service2_cost = 0

print("Davy's auto shop services")

print("Oil change -- $35, Tire rotation -- $19, Car wash -- $7, Car wax -- $12")

service1 = input("Select first service: ")

service2 = input("Select second service: ")

if service1 == "Oil change":

   service1_cost = 35

elif service1 == "Tire rotation":

   service1_cost = 19

elif service1 == "Car wash":

   service1_cost = 7

elif service1 == "Car wax":

   service1_cost = 12

elif service1 == "-":

   service1 = "No service"

   service1_cost = 0

if service2 == "Oil change":

   service2_cost = 35

elif service2 == "Tire rotation":

   service2_cost = 19

elif service2 == "Car wash":

   service2_cost = 7

elif service2 == "Car wax":

   service2_cost = 12

elif service2 == "-":

   service2 = "No service"

   service2_cost = 0

print("- - -")

print("Davy's auto shop invoice")

print("Service 1: " + service1 + " costs $" + str(service1_cost))

print("Service 2: " + service2)

print("Total: $" + str(service1_cost + service2_cost))

Explanation:

- Initialize the variables for cost values

- Ask the user for the services

- Depending on the user choice, calculate the cost of each service using if else structure

- Print the chosen services, cost of each service and total cost    

3 0
3 years ago
what is the system that connects application repositories, systems, and it environments in a way that allows access and exchange
geniusboy [140]

The system that connects application repositories, systems, and it environments in a way that allows access and exchange of data over a network by multiple devices and locations is called Cloud integration.

<h3>What is the role of a cloud integrator?</h3>

Cloud-based integration is a type of systems integration business that focuses on data, process, service-oriented architecture, and application integration. It is offered as a cloud computing service.

Therefore, An integrator of the cloud offers services to help organizations integrate their software programs. Data conversion, process design, architecture, and application setup fall under this category.

Learn more about Cloud from

brainly.com/question/9759640
#SPJ1

5 0
1 year ago
What is clicking in computer ​
evablogger [386]
Is this supposed to be a riddle? Or sum

Btw please mark as brainest
4 0
3 years ago
Other questions:
  • ____ are systems in which queues of objects are waiting to be served by various servers
    5·1 answer
  • A top-notch IT company is seeking an experienced leader to direct a team of experts in the development, creation, and modificati
    14·2 answers
  • Which soft skill involves the ability to work harmoniously with your colleagues and improve productivity?
    14·1 answer
  • Using C++
    15·1 answer
  • Your computer has a single hard disk w/ a single volume used by the C:\ drive. You have previously upgraded the disk to a dynami
    6·1 answer
  • Which of the following OSI layers is responsible for the segmentation, multiplexing, flow control and host-to-host communication
    6·1 answer
  • What is one way to recognize whether an online source has been copyrighted? The source features the phrase “all rights reserved.
    6·2 answers
  • Pleasee help. How do you fix this problem in discord?
    10·1 answer
  • You have just received a generic-looking email that is addressed as coming from the administrator of your company. The email say
    8·1 answer
  • Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 10000.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!