Header Ads Widget

Write a python program to print all prime number from 1 to 100.

 What is prime number:- 

                                        A number is called prime number if it divisible by only 1 and itself .

example:-  3 is divisible by 1 and 3 only.So 3 is a prime number.

                 2,3,5,7...... all are also a prime number.

code:-


# function for check prime number

def check_prime(num):
flag = 0
for i in range(2,num//2+1):
if num%i==0:
flag=1
break
if flag==1:
return 0
else:
return 1

# driver function

for i in range(1,100):
f=check_prime(i)
if f==1:
print(i,end=" ")

Output:-


1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97



Post a Comment

0 Comments