C++ Program to Check Prime Number

| Last Updated: | In: C++ Tutorial


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.

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.

Output:

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


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:

Tags: , , ,