Here is one definition.
int countprimes(int a, int b) { int numprimes = 0; int k = a; while(k <= b) { if(prime(k)) numprimes++; k++; } return numprimes; }