I think I have managed to solve this but want to make sure

#include <iostream>
#include <cmath>

using namespace std;

int main()

	int n;
	double m;
	int i = 2;
	int isPrime = true;

	cout << "Please enter a number and press enter " ;
	cin >> n;
	cout << endl;

	m = sqrt(double(n));

	cout << m;
	cout << endl;

	while (i <= m) // or (i*i<=n)
		if (n % i == 0)
			isPrime = false;

	if (isPrime)
		cout << "Number is a prime number" << endl;


		cout << "Number is not a prime number" << endl;

So what this is doing if I am correct, is calculating the square root of int n only once, then as long as double m is less than or equal to int i, it will keep looping, is this code right ?????

Last edited by shabbir; 11Aug2011 at 13:26.. Reason: Code blocks