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 is not anadvantage of simulation?
kari74 [83]

Answer: Ability to derive optimal solutions

Explanation:

One of the main disadvantages of simulation is ability to derive optimal solutions. As, the solution does not required to have a closed form and  procedure does not require any weighting and the hard constraint.  Stimulation outcome are not optimal to induced specific response because of the lack of quantitative models.

3 0
3 years ago
Hey, anyone like will u jus help meh like pleaseee
jeyben [28]

Answer:

1

Explanation:

3 0
3 years ago
Read 2 more answers
Jane wishes to forward X-Windows traffic to a remote host as well as POP3 traffic. She is worried that adversaries might be moni
chubhunter [2.5K]

Answer:

She can the following tool to protect the link:

Secure Socket Shell

Explanation:

Secure Socket Shell:

It is also known as secure shell and has short form SSH. A method that is used to secure the communication over the unprotected network. This network protocol was introduced in 1995 and its most common use include the managing of different systems as the network administrator can execute different commands remotely.

In our question, Jane can use Secure socket shell in order to communicate the information to the remote end without being monitored by the adversaries.

8 0
4 years ago
When your phone sends/receives text messages (specifically using SMS), the total data sent/received contains more than just your
Alexandra [31]

An SMS is a short code that is used by businesses to opt in consumers to their SMS programs, and then used to send text message coupons, offers, promotions to those customers that had previously opted.

Explanation:

When Someone tries to call you, the tower sends your phone a message over the control channel that tells your phone to play its ringtone. The tower gives your phone a pair of voice channel frequencies to use for the call.

The MMS and other data driven services works on the fundamental voice network and is based on the big three GSM, CDMA and TDMA network technologies. The SMS allows text messages of 160 characters (letters, numbers and symbols).

The text messaging is an act of composing and sending electronic messages consist of alphabetic and numeric character between two or more more mobile devices.

7 0
4 years ago
Read 2 more answers
Within a single program, __________________ allows multiple parts, or threads, to run simultaneously.
jekas [21]
<span>It should be single-user/multitasking os.</span>
4 0
4 years ago
Other questions:
  • What type of mitigation provision is utilized when redundant communications links are installed?
    8·1 answer
  • Adding functionality to a Button is easy when you use the IDE. After you have dragged a Button onto a Form, you can ____ it to c
    7·1 answer
  • The internet is best described as a vast
    7·2 answers
  • Consider a system that contains 32K bytes. Assume we are using byte addressing, that is assume that each byte will need to have
    10·1 answer
  • Which kind of blocks is used to hold values​
    7·1 answer
  • JAVA
    10·1 answer
  • Write a function called changeCharacter that takes three parameters – a character array, its size, and the replacement character
    15·1 answer
  • How can blockchain be used to support sustainable business practices?
    8·1 answer
  • (50 POINTS)
    12·1 answer
  • What is the difference between a free-form outline and a modified outline?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!