My goal is to make a program that asks the user to input a positive integer n that is greater than 1. The program is then supposed to display all the prime numbers in the interval [2,n].
I came up with the following code. It doesn't work, as nothing is outputted after entering an integer.
My strategy was to make a function called 'Prime' that returns a 1 if it is not prime, and a 7 if it is prime. I then use this function in Main.
What I am I doing wrong? I would appreciate feedback.
The loop at line 26 never completes.
On the very first iteration it will either return 1 or it will return 7.
For a number to be "not prime" it is sufficient to find that there is a single factor.
But for a number to be prime, it is necessary to test more than a single factor, it is necessary to test all possible divisors (or some optimised version) and show that none of them are factors.