I was doing some practice for testing the prime number and I used the 'sqrt' command but my compiler showed an error. I'm not sure why. I was wondering if you guys could give me some advice.
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int n;
int i;
int is_prime = true;
cout << "Enter a number: ";
cin >> n;
i = 2;
while (i <= sqrt(n))
{
if (n % i == 0)
is_prime = false;
i++;
}
if (is_prime)
cout << "Number is prime." << endl;
else
cout << "Number is not prime." << endl;
return 0;
}
I changed the 'i' to float but that didn't work either. I'm very new to C++.