Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   C Twinprimes finder (http://www.go4expert.com/forums/c-twinprimes-finder-t8768/)

SpamAreI 12Feb2008 12:29

C Twinprimes finder
 
Hi I'm trying to write a short program to find twinprimes (a prime with a difference of 2 to the prime below it). I've been scanning and rewriting it for hours, but can't figure out what's wrong :/

Code:


#include<stdio.h>
main()
{
  int noprime=0, num=2, count=0;
  int primes,test1,firstP;
  printf("How many twin primes do you want to find?");
  scanf("%d",&primes);
  while(count<primes){
    noprime=0;
    for(test1=1;test1<num;test1++){
      if(num%test1==0){
        noprime=1;
        break;
      }
      if(noprime){
        printf("%d is not prime\n",num);
        num++;
      }
      else{
        if(num-firstP==2){
          printf("%d is a prime and a twin prime in the prime pair %d%d\n",num,firstP,num);
          firstP=num;
          num++;
          count++;
        }
        else{
          printf("%d is prime but not a twin prime\n",num);
          firstP=num;
          num++;
        }
      }
    }
  }
}


SpamAreI 12Feb2008 12:39

Re: C Twinprimes finder
 
nevermind, I got it O.o


All times are GMT +5.5. The time now is 11:03.