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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: