Subscribe For Free Updates!

We'll not spam mate! We promise.

Thursday, 6 September 2012

C++ code to find prime numbers between two numbers


#include <iostream.h>
#include <conio.h>

int main()
{
clrscr();
int n_div;
int num1,num2;
int divisor;
cout<<"Enter starting number: ";
cin>>num1;
cout<<"Enter ending number: ";
cin>>num2;
cout<<"\n";
cout<<"Prime numbers are: ";
while(num1<=num2)
{
divisor=1;
n_div=0;
while(divisor<=num1)
{
 if(num1%divisor==0)
{
 n_div++;
}
divisor++;
}
if(n_div==2)
{
 cout<<num1<<" ";
}
num1++;
    }
getch();
return 0;

}

Socializer Widget By CodingLovers
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment