I am having a problem with this code. Although it should say that this number is not prime, as i put a ridiculously large number that i know to be nonprime (252345435465, or even 1000000000000 as an example), it states that the number is prime.
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
int i;
int prime = true;
cout << "Type in a number and press ENTER: ";
cin >> n;
i = 2;
while (i <= sqrt(n)) {
if (n % i == 0) {
prime = false;
break;
}
i++;
}
if (prime)
cout << "The number is prime" << endl;
else
cout << "The number is NOT prime" << endl;
system("PAUSE");
return 0;
}
Is there something I'm doing wrong?