- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Any whole number which is greater than 1 and has only two factors that is 1 and the number itself, is called a prime number. Other than these two number it has no positive divisor. **For example** −

7 = 1 × 7

Few prime numbers are − 1, 2, 3, 5, 7, 11 etc.

- 1. Take integer variable A
- 2. Divide the variable A with (A-1 to 2)
- 3. If A is not divisible by any value (A-1 to 2), except itself it is a prime number.
- 4. Repeat this for all the numbers starting from 2 to the required limit.

public class First100Primes { public static void main(String args[]){ for(int i = 2; i<=100;){ int prime = 1; for(int loop = 2; loop <=i; loop++) { if((i % loop) == 0 && loop!=i) { prime = 0; } } if (prime != 0){ System.out.println(i+" is a prime number"); i++; } else i ++; } } }

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

- Related Questions & Answers
- Program to print numbers from 1 to 100 without using loop
- Python program to print all Disarium numbers between 1 to 100
- Python program to print all Happy numbers between 1 and 100
- Java program to print a prime number
- Python program to print all Prime numbers in an Interval
- Program to print prime numbers in a given range using C++ STL
- Print the nearest prime number formed by adding prime numbers to N
- Print prime numbers with prime sum of digits in an array
- Java program to print the Armstrong numbers between two numbers
- Program to print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime Using C++
- Java Program to get the prime numbers with BigInteger type
- Write a program in Python to generate any random five prime numbers between 100 to 150 in a Series
- Print prime numbers from 1 to N in reverse order
- How will you print numbers from 1 to 100 without using loop in C?
- How to Print all Prime Numbers in an Interval using Python?

Advertisements