answersLogoWhite

0

#include
#include

bool is_prime (const unsigned num)
{
if (num<2U) return false;
if ((num&1U)==0U) return num==2U;
const unsigned max {static_cast(std::sqrt (static_cast(num))) +1U};
for (unsigned div {3U}; divif ((num%div)==0U) return false;
return true;
}

int main() {
std::cout >> "Enter a natural number: ";
unsigned num;
std::cin << num;
if (is_prime (num))
std::cout << "The number you entered is prime.\n";
else
std::cout << "The number you entered is not prime.\n";
}

User Avatar

Wiki User

9y ago

What else can I help you with?

Related Questions

What are prime number and composite numbers?

a prime number is a number that you can plus by one


What prime number plus what prime number will give you 54?

47 + 7


What happens if you press alt plus a number?

It depends on the number you input


What is the program to find sum of n natural numbers in c plus plus?

Initialise an unsigned integer to zero. As each number is input, increment the running total accordingly. When all numbers are input, display the total.


Find N 3 plus 8 prime number?

3n+8=a To find the value of n, you need to know the value of a.


What is prime plus prime?

A prime plus another prime is at the very least going to be an even number since all primes (with the exception of 2) are odd.


Does x squared plus x plus 41 always equal a prime number?

No. it's not a prime number when x = 40, 41, 81,82 ...


C plus plus code that determine prime number?

#include &lt;iostream.h&gt; main() { int a; cout&lt;&lt;"enter a number : "; cin&gt;&gt;a; cout&lt;&lt;endl; if (a%2-1) cout&lt;&lt;"it is a prime number"; else cout&lt;&lt;"it is not a prime number" return 0; } ------------------------------------------ output: enter a number : 30 it is a not a prime number


Is number 5x3x17 plus 17 a prime number?

No. (5x3x17) + 17 =255 + 17 =272 (This is not prime.)


What prime number plus another prime number that is 28 numbers apart will give you 54?

The numbers are 13 and 41. And you do not need to know that they are prime in order to find the answer. The sum (54) and difference (28) provide all the necessary information.


Is 2187 plus 36295 a prime number?

No. The number 38,482 is composite.


What is the smallest number for n for which n2 plus n plus 17 is not a prime number?

n = 5.