Javatpoint Logo
Javatpoint Logo

Program to print all prime numbers between 1 and 100

Prime Numbers:

Prime numbers are the natural numbers that can be divided by their self or by 1 without any remainder.

For example: 2, 3, 5, 7, 11, 13, 17 etc.

NOTE: 2 is the only even prime number.

In this program, we need to print the prime numbers between 1 and 100 only.

Algorithm

  • STEP 1: START
  • STEP 2: SET ct =0, n=0, i=1,j=1
  • STEP 3: REPEAT STEP 4 to STEP 11 until n<25
  • STEP 4: SET j= 1
  • STEP 5: SET ct = 0
  • STEP 6: REPEAT STEP7 to STEP 8 UNTIL j<=i
  • STEP 7: if i%j = = 0 then ct =ct +1
  • STEP 8: j = j + 1
  • STEP 9: if ct= 2 then print i
  • STEP 10: n = n +1
  • STEP 11: i = i +1
  • STEP 12: END

Java Program

Output:

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

C progam

Output:

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

Python Program

Output:

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 

C# Program

Output:

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

PHP Program

Output:

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 
Next Topic#




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA