#include "g:\victor\vitodef.h"

// Prototypes

int numprimes(int,int);
int prime(int);
void printchar(char);
void skiplines(int);
void drawline(int, char);
void drawblanks(int);

// function definitions

int numprimes(int low, int high)
// calculates number of primes between high and low
{
int cnt=0; int num=low;
for (; num<=high; num++)
	{
	if (prime(num))
		cnt++;
	}
return(cnt);
}

int prime(int number)
// finds prime numbers
{
int div;
for (div=2; div<=number/2; div++)
	{
	if (number % div == 0)
		return(0);
	}
return(1);
}

void printchar(char ch)
// prints character ch
{
cprintf("%c",ch);
textcolor(random(15)+1);
textbackground(BLACK);
}

void skiplines(int howmany)
// goes to new line howmany times
{
for (; howmany > 0; howmany--)
	cout << endl;
}

void drawline(int len, char ch)
// prints line of len characters c
{
for (; len>0; len--)
	printchar(ch);
}

void drawblanks(int number)
// prints number blank spaces
{
drawline(number, ' ');
}

void main(void)
//tests primes function

{
int low=0, high=100;
clrscr();
for (; high<=5000; low+=100)
	{
	cout << low << " - "  << high << " ";
	drawline(numprimes(low,high),'*');
	cout << "\n";
	skiplines(1);
    high+=100;
    }
getche();
}

