C++ Program to Check Prime Number

Prem Tiwari - - 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.

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

About: Prem Tiwari

Prem Tiwari is the founder of FreeWebMentor.com and also 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.

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.