Do you have to use the sqrt() function?

Here's a code I did a while ago, it lists prime numbers from a given range.

It can be modified to just tell if a number is prime.

Hope it Helps

Code:

// Prime Number Notes 10-7-2011.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include "resource.h"
using namespace std;
void DisplayEvens(int, int);
int main()
{
// Declare and init two intergers
// Beginning num and ending numbers
int intBeginNum = 0;
int intEndNum = 0;
// Prompt user for range
cout << "Enter a beginning number for the range:" << endl;
cin >> intBeginNum;
cout << "Enter an ending number for the range:" << endl;
cin >> intEndNum;
DisplayEvens(intBeginNum, intEndNum);
system ("pause");
return 0;
}
void DisplayEvens(int intBeginNumDE, int intEndNumDE)
{
// Initialization and declare
// this is done inside of for loop
bool bolPrime = false;
for (int i = intBeginNumDE; i <= intEndNumDE; i++)
{
for (int j = 2; j < 10; j++)
{
if (i != j && i != 1)
{
if (i % j != 0)
bolPrime = true;
else
{
bolPrime = false;
break;
}
}
}
if (bolPrime)
cout << "Prime Number: " << i << endl;
}
return;
}