C++ Program to find Prime Numbers In a Give Range

ad+1

Program:

// Program By http://solutionscpp.blogspot.com
// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int start=0,end=0;
    int found=0,count=0;

    cout<<"Enter Staring Number of Range:  ";
    cin>>start;
    cout<<"Enter Ending Number of Range:  ";
    cin>>end;

    for(int i=start;i<=end;i++)
       {
           for(int j=2;j<=sqrt(i);j++)
               {
               if(i%j==0)
                  count++;
               }
               if(count==0&&i!=1)
               { found++;
                 cout<<"Prime Number = "<<i<<endl;
                 count=0;
               }
               count=0;
       }

 cout<<"Total Prime Number Between Range "<<start<<" to "<<end<<" = "<<found<<endl;

}


 

Output:

 

1 comment: Leave Your Comments