0
Functions in c++
How to write a program with functions to obtain the prime numbers up to what ever the number entered by the user in c++.. Thank you
1 Resposta
+ 1
You can't enter any number in C++, as the maximum number supported by unsigned long long is 2^63-1.
Now, to calculate any prime number between 0 and this number, you may use this function:
bool prime(unsigned long long a)
{
if(a == 0 || a == 1) return false;
if(a == 2) return 2;
for(int i=0;i<sqrt(a);i++)
if(a%i==0) return false;
return true;
}