Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

prime numbers 1 to 100

for i in range(101): #range can be changed upto any positive integer
       j=2    #j is the divider  
       while i%j!=0 or i==2:  #checking if (i/j) gives a remainder, 
                              #also if i=2, the loop still runs or else 2 is not considered a prime
              j+=1  #increasing j by 1
              if j>i/2:  #check only dividers(j) of i upto i/2 cause above that ur just reapeating the same factors
                     print(i,'is a prime')
                     break  #breaks while loop
 
PREVIOUS NEXT
Tagged: #prime #numbers
ADD COMMENT
Topic
Name
3+6 =