Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. void primegen(int count)
  2. {
  3.     int ret[count];
  4.     ret[0] = 2;
  5.     int totalprimes = 1, next = ret[0], top, found, i;
  6.     found = 0;
  7.     while (totalprimes < count) {
  8.         next++;
  9.         top = next >> 1;
  10.         top++;
  11.         found = 0;
  12.         while (!found) {
  13.             found = 1;
  14.             for (i = 2; i <= top; i++)
  15.                 if (next % i == 0) {
  16.                     found = 0;
  17.                     next++;
  18.                 }
  19.         }
  20.         ret[totalprimes] = next;
  21.         totalprimes++;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement