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
How can you quickly locate emails with large attachments.
IgorC [24]

To locate emails with large attachments, go to your email and then choose the option of Choose File > Cleanup Tools > Mailbox Cleanup.

Here , one has to Log into their email account and open their inbox and then use the Search Mail bar and type Size to locate or they Set the Find items that are larger than to 9999 and then one has to click Find.

<h3>How do I find emails by attachment size?</h3>

This can also be done for messages that has a size equal to or bigger than 25.

One has to open their message and then they have to right-click on the attachment. You can choose Save As and save to the location of the choice you want.

Learn more about attachments from

brainly.com/question/978078

4 0
2 years ago
A cell's address, its position in the workbook, is referred to as a ________________ when it is used in a formula.
Inga [223]

Answer:

A cell's address, its position in the workbook, is referred to as a <u>cell reference</u>  when it is used in a formula.

5 0
2 years ago
A Function checkMe takes three parameters, a character and two integers. If the sum of the two integers is negative, and the cha
Paul [167]

Answer:

Check the explanation

Explanation:

Here is the program with function definition and two sample calls.

Code:

#include <iostream>

using namespace std;

//checkMe FUNCTION which takes values a, b and c

void checkMe(char &a, int &b, int &c)

{

//if sum of b and c is negative and a is 'n', b and c are set to 0, otherwise a is set to 'p'

if((b+c)<0 && a=='n')

{

b = 0;

c = 0;

}

else

{

a = 'p';

}

}

int main()

{

//first test case when else part is executed

char a = 'n';

int b = 5;

int c = 6;

 

checkMe(a, b, c);

 

cout<<a<<" "<<b<<" "<<c<<endl;

 

//second test case when if part is executed

a = 'n';

b = -4;

c = -5;

 

checkMe(a, b, c);

 

cout<<a<<" "<<b<<" "<<c<<endl;

return 0;

}

Kindly check the Output below:

7 0
3 years ago
Match the spacing options to their meanings.
Maslowich

Before text = indents paragraph to the right  

First line = indents the start of a paragraph

Register-true = formats page styles  

Line spacing = manages space between two lines  

The first line always gets indent to specify that it is a start of the paragraph

Line spacing always focus on the number of spaces between lines. There are various values available to give spacing according to the need. Register- true is used to format all the page styles and do other related configurations.

3 0
3 years ago
Read 2 more answers
What is a industrial engineer?​
Eddi Din [679]

Answer:

Industrial Engineers develop job evaluation programs and find ways to elimimate wastefulness in productions.

3 0
3 years ago
Other questions:
  • Write a class named Taxicab that has three **private** data members: one that holds the current x-coordinate, one that holds the
    9·1 answer
  • Which of the following guidelines about forwarding e-mail messages is most appropriate?
    12·2 answers
  • Create a simple main() that solves the subset sum problem for any vector of ints. Here is an example of the set-up and output. Y
    12·1 answer
  • Why might a variable used for output have to be of a different type then a variable used for input?​
    15·1 answer
  • Think about some of the most memorable and forgettable games ever created. They can be games that were discussed in this unit or
    10·1 answer
  • Which is a basic job requirement for a career in corrections services?
    13·1 answer
  • Mr. Stevens is the principal of a high school. Why might he want to export data from a database of students’ exam scores?
    14·2 answers
  • Question :
    6·1 answer
  • You can perform an in-place upgrade to Windows 7 from both Windows XP and Windows Vista
    11·2 answers
  • FOLLOW INSTRUCTIONS BELOW , WRITTEN IN JAVA LANGUAGE PLEASE AND THANK YOU !
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!