Fast Enterprises Interview Question

Write code to list the first 20 prime numbers

Interview Answer

Anonymous

Jan 10, 2016

primeCounter = 0. Create for loop for(i = 2; primeCounter < 20; i++), then test in for loop if "i" is prime. if "i" is prime then print the value of i, and primeCounter++. This will give print the first 20 prime numbers in the array once the function completes. You can create a simple isPrime(int value) function from some of my other answers listed on here.