1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include<iostream>
#include<cmath>
#include <cstdlib>
using namespace std;
int main()
{
int count=1;
int prime=3;
int fact=2;
int primeplus=3;
while(count<6)
{
fact=2;
//for first iteration,
while(fact<prime) //fac = 2, prime = 3, condition = true
{
if(prime%fact==0) //3%2 != 0, condition= false, if body does not execute
{
prime++; //failed to increment
break;
}
fact++; //fac = 3, and while ends coz (fact < prime) is not true
}//Conclusion: this was useless
if(primeplus-prime==2) //primeplus = 3, prime = 3, diff = 0, condition false, body does not execute
{
cout<<prime<<" and "<<primeplus<<" are twin primes."<<endl;
count++;
}
if(prime==fact) //yes prime == fact as a result from the loop: while(prime < fact)
{
primeplus=prime; //they were already the same
}//conclusion: (..)
/* i dont know how you are computing the prime number,
coz even if all of these were true, primeplus does not change anywhere
and will always remain 3, hence, your condition: if(primeplus - pime == 2) will never evaluate to true
*/
}//count never reaches 6, hence while(count < 6) runs for ever. INFINITE LOOP
system("PAUSE");
}
|