Anonymous

How do I write a program that prints all prime numbers from 1 to a user-specified value, n?

1

1 Answers

Anonymous Profile
Anonymous answered

I don't know if you've come across it before, but if you're looking for a method to prints all prime numbers from 1 to a user-specified value, then you may want to check this out:

http://technology.blurtit.com/1464031/write-a-program-that-prints-prime-numbers-between-1-to-n-number-n-should-be-accepted-as

The question title is pretty similar, although I noticed the answer hasn't been compiled, so there is still some work to do..

Alternatively - the following answer was voted as a good answer on another QA& site, maybe that would be more useful for you - again, a very similar question title:

Using pseudo code, write a program that prints all prime numbers from 1 to a user specified value of "n"?

(this question specifies an answer using "While-do, If-then-else, Do-while, etc.")

int x = 1
for int x < n:
int y = 1;
boolean isPring = true;
for int y<=x:
if x%y != 0:
isPrime = false;
end if;
y = y +1;
end for;
x = x+1;
if isPrime:
print x;
end if;
end for;

Answer Question

Anonymous