Advertisement
rdrewd-facebook

find20primes.c

Sep 27th, 2014
1,674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. main (){
  4.     int j;
  5.     int primecnt;
  6.     int primes[20];
  7.     primecnt=1;
  8.     primes[0]=2;
  9.     int cand=3;
  10.     while (primecnt < 20){
  11.         for (j=0; j<primecnt; j++){
  12.             if (cand % primes[j] == 0){
  13.                 goto notprime;
  14.             }
  15.         }
  16.         primes[primecnt]=cand;
  17.         primecnt += 1;
  18.       notprime:
  19.         cand += 2;
  20.  
  21.     }
  22.     for (j=0; j<primecnt; j++){
  23.         printf("%d\n", primes[j]);
  24.     }
  25.     exit(0);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement