Last Updated: 7 Feb, 2021

All Prime Number

Easy

Problem statement

Given an integer N, print all the prime numbers that lie in the range 2 to N (both inclusive).

Print the prime numbers in different lines.

Input format :
 The only line of input contains a single integer N.
Output format :
Print all Prime numbers in a separate line.
Constraints
1 <= N <= 100

Approaches

01 Approach

In the outer loop, we are iterating i from 2 to n, and at the beginning of the loop set, the value of the flag to True after that in the nested loop iterate j from 2 to i check if i is divisible by j it means i has a factor and it is not a prime. Finally, check if the flag's value is True, then it is prime else, not prime.

If it is prime print i, else do nothing.