Advertisement
Guest User

Untitled

a guest
Oct 19th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1.  for (int primeTest = 2; primeTest <= userLimit; primeTest++) // Declares primeTest for the for loop and checks each number until it hits user input
  2.             {
  3.                 isPrime = true;         // Sets isPrime to true because it is unknown
  4.                 visualPrime += "X";     // Adds one X for output purposes
  5.                 if (true)     // 2 will fail the for loop so this skips it
  6.                 {
  7.                     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
  8.                     {
  9.                         if (primeTest % primeCount == 0)    // If primeTest modulus is equal to 0 then the number is not prime
  10.                             isPrime = false;                // If found true sets isPrime to false
  11.                     }
  12.                 }
  13.                 if (isPrime == true)    // If isPrime is still equal to true then it is a prime number
  14.                     Console.WriteLine(visualPrime + " " + primeTest); // Outputs the X's and the prime number in primeTest
  15.  
  16.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement