{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Prime examples

# Prime examples - PrimeArray[PrimeCount = i int...

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

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 int PrimeArray[10000] int PrimeCount int CheckForPrime(int i) void CalcPrimes() { int i PrimeArray[0] = 2 PrimeCount = 1 for (i = 3 if (CheckForPrime(i))

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

View Full Document
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

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online