about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

                    Prime number program in C Plus Plus

Prime number program in C Plus Plus

Prime number finding is the basic task in the mathematics. As the computers are taking the place of men in all type of calculations. Human are becoming to be more dependent upon the calculators and other computer software instead of their own brain.


Then as every type of calculations become the computerized, and computer programs are doing the sophisticated mathematical calculations in seconds which human solves after the great wastage of time and headache.


Program to find the prime number was also developed to ease the human. I have find out different ways to find the prime number and choose these easiest one for my readers. So that they can easily find out an understandable program by visiting only one site.


                                                    Prime number


Before we develop a program for the prime number finding, it is to be cleared that, Prime number is a number which has only two divisible number itself and 1.


And all other numbers which have more than two divisible is not prime.

 

The given number is prime or not. This C++ program will take a number form the user as input and will tell the user that this number is Prime or not. And if not prime the reason why it is not prime.

 

                                                           Prime number program in C++

Code

//softoset.blogspot.com

#include<iostream>

#include<iomanip>

#include<process.h>

using namespace std;

int main()

{

            int j,n;

            cout<<"Enter a Number\n";

            cin>>n;

            for(j=2;j<n/2;j++)

            {

                        if(n%j==0)

                        {

                                    cout<<"It is Not A Prime number divisible by :"<<j<<endl;

                                    exit(0);

                        }

            }

            cout<<"It is a Prime Number"<<endl;

            return 0;

}

 

                                                Prime number program in C++

Output

 

The sample run of this program has been captured for you in this screenshot.

 

 

 

Prime number program in C Plus Plus

You can see that when user has entered the number 5 program outputs that it is a prime number.

Now see the next use case of this program.

 

 

 

Not       Prime number program in C Plus Plus

 

Here user has entered the number 20 and program tell him that your entered number is not  Prime because it is divisible by 2.

 

 

That’s it and Thank You.

 

 

 


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents