Be the first user to complete this post

  • 0
Add to List
Beginner

316. Print First N Prime Numbers

Objective: Given a number N, write a program to print first N prime numbers.

What is Prime number:??
A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A number is either divisible by 1 or by number by itself.

Example:

N = 5
2 3 5 7 11

N = 10
2 3 5 7 11 13 17 19 23 29

Approach:

  • Start from number 2 to till we find N prime numbers
  • Check for each number if it is prime, if yes then increment the prime count.
  • Check this - Check if Given number is Prime
  • Check the code, its self explanatory.

Output:

2 3 5 7 11
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71