MFC: An off-by-one malloc size was corrupting the installer's memory,
[dragonfly.git] / contrib / top / prime.c
blobb0d65424b5e0baa03bf9516bcd974ffcd41aafd9
1 /*
2 * Prime number generator. It prints on stdout the next prime number
3 * higher than the number specified as argv[1].
4 */
6 #include <stdio.h>
7 #include <math.h>
9 main(argc, argv)
11 int argc;
12 char *argv[];
15 double i, j;
16 int f;
18 if (argc < 2)
20 exit(1);
23 i = atoi(argv[1]);
24 while (i++)
26 f=1;
27 for (j=2; j<i; j++)
29 if ((i/j)==floor(i/j))
31 f=0;
32 break;
35 if (f)
37 printf("%.0f\n", i);
38 exit(0);