Prime Number Generation

How to write a program that will print all the prime number between 1 to n?

I can write the program to check whether a number is prime or not but I want to write a program that will print all prime number. Here I will take the input value n from keyboard. Example: If n = 10 than the output sceen will print: 2 3 5 7 (as 1 is not a prime number).

How can I write the program? Can anyone help me?
Set a value to 2.

For all numbers less than value and greater than one, calculate value%number. If it's zero, the number is prime.

Increment value and repeat until value is the same as the user's input.
Last edited on
Topic archived. No new replies allowed.