Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (int primeTest = 2; primeTest <= userLimit; primeTest++) // Declares primeTest for the for loop and checks each number until it hits user input
- {
- isPrime = true; // Sets isPrime to true because it is unknown
- visualPrime += "X"; // Adds one X for output purposes
- if (true) // 2 will fail the for loop so this skips it
- {
- for (int primeCount = 2; primeCount * primeCount <= primeTest && isPrime == true; primeCount++) // declares primeCount and checks each number until either the number is found to be non prime or until square is greater than testing number
- {
- if (primeTest % primeCount == 0) // If primeTest modulus is equal to 0 then the number is not prime
- isPrime = false; // If found true sets isPrime to false
- }
- }
- if (isPrime == true) // If isPrime is still equal to true then it is a prime number
- Console.WriteLine(visualPrime + " " + primeTest); // Outputs the X's and the prime number in primeTest
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement