



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
pjjjjjjjjjjjjjjjjhjhhhhghgggggfffffcf
Typology: Lecture notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!
Aim: To write a Python program to find GCD of two numbers. Algorithm:
1. Define a function named compute GCD() 2. Find the smallest among the two inputs x and y 3. Perform the following step till smaller+ Check if ((x % i == 0) and (y % i == 0)), then assign GCD=i 4. Print the value of gcd
def computeGCD(x, y): if x > y: smaller = y else: smaller = x for i in range(1, smaller+1): if((x % i == 0) and (y % i == 0)): gcd = i return gcd num1 = 54 num2 = 24
print("The GCD. of", num1,"and", num2,"is", computeGCD(num1, num2)) Sample Output: $python main.py
n = int(input("Enter the upper limit: ")) print("Prime numbers are") for num in range(0,n + 1):
1 if num > 1: Sample Output: $python main.py Enter the upper limit: 20 Prime numbers are 2 3 5 7 11 13 17 19 ('The GCD. of', 54, 'and', 24, 'is', 6)
Aim: To write a Python program to find first n prime numbers. Algorithm:
print("The maximum number is %d"%maxno)