source: trunk/third/top/prime.c @ 9084

Revision 9084, 458 bytes checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r9083, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Prime number generator.  It prints on stdout the next prime number
3 * higher than the number specified as argv[1].
4 */
5
6#include <math.h>
7
8main(argc, argv)
9
10int argc;
11char *argv[];
12
13{
14    double i, j;
15    int f;
16
17    if (argc < 2)
18    {
19        exit(1);
20    }
21
22    i = atoi(argv[1]);
23    while (i++)
24    {
25        f=1;
26        for (j=2; j<i; j++)
27        {
28            if ((i/j)==floor(i/j))
29            {
30                f=0;
31                break;
32            }
33        }
34        if (f)
35        {
36            printf("%.0f\n", i);
37            exit(0);
38        }
39    }
40}
Note: See TracBrowser for help on using the repository browser.