C++ Program to Check Prime Number

Bellow program will check the entered number by the user is whether a number is a Prime number or Not a Prime number by using the C++. I assume you have basic knowledge of C++ and C++ if, if…else and Nested if…else.

C++ Program to Check Prime Number

What is Prime Number?

A prime number is a number which is exactly two positive divisors, 1 and the number itself, like if the user entered 13, then the entered number is a prime number. Below are the prime numbers between 1 to 100, which are only divisible by itself only.

How to Check Prime Number?

Check if the entered number by the user is only divisible by 1 or itself, then it is a prime number. In this program we used the for() loop and IF…ELSE statement. See the below example.


First run:
Enter an integer number: 115
115 is not a prime number
Second run:
Enter an integer number: 13
13 is a prime number

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article Tags: , , ,