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
kompoz [17]
3 years ago
13

Problem 5. (Greatest Common Divisor) Write a program gcd.py that accepts p (int) and q (int) as command-line arguments, and writ

es to standard output the greatest common divisor (gcd) of p and q.
Computers and Technology
1 answer:
netineya [11]3 years ago
8 0

Answer:

The following are the program in the Python Programming Language.

#import system

import sys

#define function

def gcd(p,q):

 #check that q is equal to 0

 if(q==0):

   #then, it returns the output

   return p

 #it returns the common divisor

 else:

   return gcd(q,p%q)

#get the command-line input

x=sys.argv[1]

#get the command-line input

y=sys.argv[2]

#convert input into the integer

p=int(x)

#convert input into the integer

q=int(y)

#call and print the function

print(gcd(p,q))

Explanation:

<u>The following are the description of the program</u>.

  • Firstly, we import the required package and define a function 'gcd()', pass arguments 'p' and 'q' and inside the function.
  • Set the if conditional statement to check that the variable 'q' is equal to 0 then, it returns the value of 'q' and otherwise, it returns the greatest common divisor value.
  • Finally, we set two variables 'x' and 'y' in which we get input from the command line then, convert the input of the both variable into integer and store them in other variables 'p' and 'q', after all, call and print the following function.
You might be interested in
Which is an example of a Boolean operator that evaluates as TRUE?
ladessa [460]

The expression NOT (3+2=7) evaluates as TRUE because is is NOT the case that 3+2=7.

Let me know if you have any questions.

4 0
2 years ago
X = 10<br> y = 20<br> x &gt; У<br> print("if statement")<br> print("else statement")
Ksenya-84 [330]

Answer:

n

Explanation:

n

5 0
3 years ago
Nikki sent flyers in the mail to all houses within the city limits promoting her computer repair service what type of promotion
Jlenok [28]

Direct marketing (APEX)


6 0
3 years ago
Read 2 more answers
Matt expects to get his first paycheck today. What deductions may be listed on his paycheck stub?
Bingel [31]
Social security
Also if he has any taxs they will be deducted
4 0
3 years ago
To rename a worksheet, you change the text on the ? HELP ASAP
prohojiy [21]
If this is Excel, it would be C. Sheet tab
5 0
2 years ago
Other questions:
  • When using a template to compose a memorandum which key on the keyboard moves the cursor to the next field
    15·1 answer
  • How can you add and remove categories from a previously created chart? A. Click the Format tab. B. Click the Chart Styles button
    13·2 answers
  • you where discussing software piracy with a friend and were surprised to learn how software piracy can impact your life every da
    12·1 answer
  • Write the definition of a function named quadratic that receives three double parameters a, b, c. If the value of a is 0 then th
    12·1 answer
  • PLEASE HELP !!!! WILL UPVOTE
    5·2 answers
  • What is a project?
    5·2 answers
  • Implementations <br> in c++ programming when finding lcm and gcd in c++​
    12·1 answer
  • Indica si los elementos de las imagenes son una materia prima o un material elaborado
    12·1 answer
  • Which function would you use to make sure all names are prepared for a mailing label? TODAY UPPER PROPER LOWER
    11·1 answer
  • The ratio of sparrows to bluejays at the bird sanctuary was 5 to 3 If there were 15 bluejays in the sanctuary, how many sparrows
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!