Prime examples - PrimeArray[PrimeCount++] = i } int...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 prime program Here's one that uses the array you were asking about to calculate the primes less than 100000. There are more than 9500 of t h int PrimeArray[10000] int PrimeCount int CheckForPrime(int i) void CalcPrimes() { int i PrimeArray[0] = 2 PrimeCount = 1 for (i = 3 if (CheckForPrime(i))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: PrimeArray[PrimeCount++] = i } int CheckForPrime(int i) { int j int sqrti sqrti = sqrt(i) for (j = 1 if (i % PrimeArray[j] == 0) return(0) else if (PrimeArray[j] > sqrti) return(1) return(1) } Sheet1 Page 2 i < 100000 i += 2) j < PrimeCount ++j)...
View Full Document

Page1 / 2

Prime examples - PrimeArray[PrimeCount++] = i } int...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online