Prime number from 1 to 100 in python by R4R Team

what is prime number ??

- A number which is divisible by 1 and itself only is called prime number.
example - 11,17,13,3 etc.

non-prime- 4,8,9,12,34,100 etc.

program -

def checkprime(n):
for i in range(2,int(n-1)):
if n%i==0:
return 0
return 1

print("Prime number from 1 to 100")
for i in range(1,101):
if checkprime(i):
print(i,end=" ")


output -

Prime number from 1 to 100
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


-In this program , we run the for loop from 1 to 100 and for each value we check it is prime or not, if it is prime then we print otherwise ignore.
- Here 'Checkprime' function is check that number is prime or not, if number is prime then it return 1 , if number is not prime then it return 0.


Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!