C++ Program to Check Prime Number By Creating a Function

To understand this example, you should have the knowledge of the following C++ programming topics:


Example: Check Prime Number

Output

Enter a positive  integer: 23
23 is a prime number.

In this example, the number entered by the user is passed to the check_prime() function.

This function returns true if the number passed to the function is a prime number, and returns false if the number passed is not a prime number.

The detailed logic of the check_prime() function is given inĀ our C++ Prime Number tutorial.

Finally, the appropriate message is printed from the main() function.