168k views
0 votes
Two positive integers are said to be relatively prime if their only common divisor is 1. For example, 8 and 9 are relatively prime, whereas 1 25 and 15 are not (because they have 5 as a common divisor besides 1). Write a function that takes as parameters two positive integers and returns whether they are relatively prime or not. Basic python programming

1 Answer

5 votes

Answer:

#code in python.

#function that calulate 2 numbers are relatively prime or not

def fun(x,y):

while(y):

x,y=y,x%y

return x

#user input

a=int(input("enter first number:"))

b=int(input("enter second number:"))

#call the function

if(fun(a,b)==1):

print(" Both numbers are Relatively prime")

else:

print("Both numbers are Not relatively prime")

Step-by-step explanation:

Read two numbers from user.Call the function fun() with parameter "a" & "b". In the function, it will perform Euclid algorithm to find the greatest common divisor.If it is 1 then both are relatively prime else both are not relatively prime.

Output:

enter first number:5

enter second number:125

Both numbers are Not relatively prime

enter first number:8

enter second number:9

Both numbers are relatively prime

User Bugs
by
6.1k points