All pastes #772657 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-13 23:18 UTC
rendered paste body
#include <stdio.h>
#define N 7

int isprime(int );
int k,init_prime,next_prime,run,number;


main()
{

  init_prime=3;  // oi 2 prwtoi pou anamesa tous vriskontai oi sunthetoi
  next_prime=0;
  
run=init_prime+2;
number=0;
k=1;
while(k<N)
{
  if (isprime(run))
  {
    next_prime=run;                  //vriskw ton next_prime
    number=next_prime-init_prime-1;  //to plhthos twn sunthetwn
    if (number==k)
    {
       printf("First %d consecutive composites from %d to %d\n",k,init_prime+1,next_prime-1);   //an einai o epithumhtos ton emfanizw
       init_prime=next_prime;
       k+=2;
    }
   
   } 

  run+=2;

}
 
}



//sunarthsh isprime()..elegxei an enas arithmos>2 einai prwtos


int isprime(int run)
{
 int i=2;
 int done=1;
 while (done==1 && i<run) 
  {
     if (run % i==0)
     {
       done=-1;
       break;
     }

     i++;
  }
  if (done==1)
     printf("%d is prime\n",run);
  else
    printf("%d is not prime\n",run);
  return done;
}