training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

isfirst.c (435B)


      1 /* Exercise 5.27 */
      2 
      3 int isfirst(int);
      4 
      5 int main()
      6 {
      7    int n;
      8 
      9    for(n = 1; n <= 10000; n += 2) {
     10       if(isfirst(n))
     11 	 printf("%d\t", n);
     12    } /* end for (n) */
     13 
     14    printf("\n");
     15    return 0;
     16 } /* E0F main */
     17 
     18 /* check if num is first */
     19 int isfirst(int num)
     20 {
     21    int i;
     22 
     23    for(i = 2; i <= 9; i++) {
     24       if( (!(num % i) && (num != i)) || num == 2 )
     25          return 0;
     26    } /* end for (i) */
     27 
     28    return 1;
     29 } /* eof isfirst() */
     30