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
The main activity area or the brain of the computer is called the ________
Darya [45]

Motherboard

Its a computer chip



6 0
2 years ago
The purpose of maintaining a network of digital forensics specialists is to develop a list of colleagues who specialize in areas
Rudiy27

Answer:

True

Explanation:

Computer security is basically divided into three main areas:

  1. Vulnerability/threat assessment and risk management refers to a process that requires the identification, quantification and ranking of a system's possible vulnerabilities.
  2. network intrusion detection and incident response refers to software that detects malicious activity or policy violations, and blocks them
  3. digital forensic investigation refers to the process of identifying, recovering and interpreting (or validating) electronic data.

Generally a single individual may specialize in one of these areas, that is why he/she may need help with the others.

8 0
3 years ago
Read 2 more answers
PLZ ANSWER ALL MY QUESTION. Which line of code will display the variable num rounded to the nearest tenth?
zavuch27 [327]

Answer:

A

Explanation:

5 0
2 years ago
Which is the another name of automatic sequence control calculator​
Alla [95]

Answer:

IBM Automatic Sequence Controlled Calculator (ASCC)

3 0
2 years ago
How to Ctrl + shift + F4 but in a HP laptop?​
ludmilkaskok [199]

Answer:

Hit the X Button Located on the top right corner or hit Control, Alt, Delete

Explanation:

Hitting the X button will make you exit the whole cite, or hitting Control, Alt, Delet, will make you go to the task bar, in which you can go to the bottom right of that screen and it should say end task

3 0
2 years ago
Read 2 more answers
Other questions:
  • Sue conducted an experiment to determine which paper towel is the most absorbent among three different brands. She decides to pr
    15·1 answer
  • "what should you do if the system continually reboots and you can't read the error message produced on a blue screen
    11·2 answers
  • Take some time to do some research about small businesses in your area. Select one and using HTML design a simple site that educ
    11·1 answer
  • Is there a syntax error in the following code? bool hourlyWorker = true; if (hourlyWorker) cout &lt;&lt; "The employee is an hou
    12·1 answer
  • If you design your pages using a font that your user does not have installed, the browser defaults to ____ on a macintosh.
    13·1 answer
  • The 8-bit ____ field is used by source network hosts and forwarding routers to distinguished classes or priorities in ipv6 packe
    11·1 answer
  • Meera has created a small program in Python. She wants to store elements of the same data type in an organized
    7·1 answer
  • What is computer specification
    15·1 answer
  • Bob has started a company and registered its name with the government as a private corporation. He tries to create a domain name
    12·1 answer
  • How to hack a I'd Indian brainly bot​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!