Write a Python Program to find first n prime numbers.
Program Algorithm:
1. Read the value of n
2. for num in range(0,n + 1), perform the following
3. if num%i is 0 then break
else print the value of num
4. Repeat step 3 for i in range(2,num)
Program Code:
n = int(input("Enter the upper limit: "))
print("Prime numbers are")
for num in range(0,n + 1):
# prime numbers are greater than 1
if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
print(num)
Program Output:
Enter the upper limit:25
Prime numbers are
2
3
5
7
11
13
17
19
23
Post A Comment:
0 comments: