Example 23: Prime Numbers

Learn how to calculate prime numbers.

Problem

A prime number is a natural number greater than 1 and is not a product of two smaller natural numbers.

Write a program to print all prime numbers from 1 to 300.

Example

Input Output
Nil 2
3

277
281
283
293

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Note: Try to generate prime numbers in the coding widget given below. The order, however, does not matter as it depends on your logic.

Get hands-on with 1400+ tech skills courses.