summaryrefslogtreecommitdiffstats
path: root/contrib/top/prime.c
blob: 319d0b62d74be00aced32e70ebb44ec9ecd832d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Prime number generator.  It prints on stdout the next prime number
 * higher than the number specified as argv[1].
 */

#include <math.h>

main(argc, argv)

int argc;
char *argv[];

{
    double i, j;
    int f;

    if (argc < 2)
    {
	exit(1);
    }

    i = atoi(argv[1]);
    while (i++)
    {
	f=1;
	for (j=2; j<i; j++)
	{
	    if ((i/j)==floor(i/j))
	    {
		f=0;
		break;
	    }
	}
	if (f)
	{
	    printf("%.0f\n", i);
	    exit(0);
	}
    }
}
OpenPOWER on IntegriCloud