SHARE
TWEET

Untitled

a guest Jul 18th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define NUM 100000
  5.  
  6. int main(void) {
  7.   int prime[NUM + 1];
  8.   int i, j, Limit;
  9.  
  10.   for (i=2; i <= NUM; i++) {
  11.     prime[i] = 1;
  12.   }
  13.  
  14.   Limit = (int)sqrt((double)NUM);
  15.   for (i=2; i <= Limit; i++) {
  16.     if (prime[i] == 1) {
  17.       for (j=i*2; j <= NUM; j++) {
  18.         if (j % i == 0) {
  19.           prime[j] = 0;
  20.         }
  21.       }
  22.     }
  23.   }
  24.   for (i = 2; i <= NUM; i++ ) {
  25.     if (prime[i] == 1) {
  26.       printf("%d", i);
  27.       printf("\n");
  28.     }
  29.   }
  30.   printf("\n");
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top