Write a Program in C++ which Identify the Prime Number

Prime numbers are only divisible with 1 and the Number itself. In this Problem the Program ask User to define two Bounds to Check how many Prime Numbers are their in the Range.

Source Code 


#include <iostream>
using namespace std;
int main()
{ 
 int number1,number2;
 cout<<endl<<endl<<"**************** PRIME NUMBER **************"<<endl<<endl;
 cout<<"Please Enter Lower Bound: ";
 cin>>number1;
 cout<<"Please Enter Upper Bound: ";
 cin>>number2;
    while(number1<number2) 
 {
  if(number1==2)
  {
   cout<<"2"<<endl;
  }//if(number1==2)
  for (int count=2; count<number1; count++)
        {
            if (number1 % count == 0)
   {
    break;
   }//if (number1 % count == 0)
            else
   {
    if (number1 == count+1)
     cout << number1 <<endl;
   }//end else
        }//for (int count=2; count<number1; count++)
  number1++;
 }//while(number1<number2) 
return 0;
}


Output of the Program


Prime Number

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment