Given a number N, the task is to print the first N prime number from 1 to N.
Input: N = 10 Output: 2, 3, 5, 7 Input: N = 5 Output: 2, 3, 5
- First take the number N as input.
- Then use a for loop to iterate the numbers from 1 to N
- Then check for each number to be a prime number. If it is a prime number, print it.
Below is the implementation of the above approach:
Prime numbers between 1 and 100 are: 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 to print all Prime numbers in an Interval
- Print the nearest prime number formed by adding prime numbers to N
- Print prime numbers with prime sum of digits in an array
- Print prime numbers in a given range using C++ STL
- Print all prime numbers less than or equal to N
- Print prime numbers from 1 to N in reverse order
- Print all Semi-Prime Numbers less than or equal to N
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- C Program for efficiently print all prime factors of a given number
- Efficient program to print all prime factors of a given number
- Program to print characters present at prime indexes in a given string
- Java Program for efficiently print all prime factors of a given number
- Program to find sum of prime numbers between 1 to n
- Program to find Prime Numbers Between given Interval
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.