Prime Numbers Between 2 Numbers


Here is my first Program for you..
Its a program to Print the Prime numbers Between 2 number..


#include<iostream.h>
int main()
{
int n1,n2,i,j,count=0;
cout<<"ENTER THE EXTENT: ";
cin>>n1>>n2;
for(i=n1;i<=n2;i++)  \\to get all numbers between the 2 number
 {
 for(j=2;j<i;j++)       \\to check the prime numbers
   {
    if(i%j==0)
    break;
   }
  if(j<i||i==1||i==0)
  ;
  else
{
cout<<"\n\t"<<i;
count++;
}
}
cout<<"\n\n\tTHERE ARE "<<count<<" PRIME NO.S BETWEEN "<<n1<<" & "<<n2;
return 0;
}


This is the preview of the code..

Any dout on this program you can comment..  

No comments:

Post a Comment