0

Hello i am quite stumped with a function to print the following results:

Start End Number of Primes

1 1000 168

1001 2000 135

2001 3000 127

3001 4000 120

4001 5000 119

5001 6000 114

6001 7000 117

7001 8000 107

8001 9000 110

9001 10000 112

…

…

…

49001 50000 98

Total primes in the first 50 chiliads: 5133

Average number per chiliad: 102.66

I have some pseudo code and the function for determining whether or not a number is prime. but i am unable to figure out how to write the function to display the ranges and the counts.

Any help would be much appreciated.

Here is my pseudo-code and my function to determine if a number is prime:

```
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// funtions
bool isPrime (long num);
// Returns true if n is a prime, else false
long primeCount (long x, long y);
// Returns the number of primes between x and y, inclusive.
int main()
{
// create a loop that calls primeCount(x,y) to test 1000 numbers at a time
/*
use the value returned from primeCount to output results
// end of the loop
// output final statistics
}
longprimeCount (long x, long y)
{
// loop through all of the thousand numbers
// call isPrime to check each number
// some kind of logic to deal with the result of isPrime
// return how many primes found between x and y
}
bool isPrime (long num)
{
// determine if num is a prim number
// return true if it is
// return false if it is not
}
bool isPrime(int n)
{
if((n == 0)||(n == 1))
return false;
int factors = 2;
numPrimes++
for(int i=2; i<=((int)sqrt((double)n)); i++){
if(n%i == 0){
factors++;
break;
}
}
if(factors == 2)
return true;
return false;
}
```