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

Revision 16185, 477 bytes checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16184, 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 <stdio.h>
7#include <math.h>
8
9main(argc, argv)
10
11int argc;
12char *argv[];
13
14{
15    double i, j;
16    int f;
17
18    if (argc < 2)
19    {
20        exit(1);
21    }
22
23    i = atoi(argv[1]);
24    while (i++)
25    {
26        f=1;
27        for (j=2; j<i; j++)
28        {
29            if ((i/j)==floor(i/j))
30            {
31                f=0;
32                break;
33            }
34        }
35        if (f)
36        {
37            printf("%.0f\n", i);
38            exit(0);
39        }
40    }
41}
Note: See TracBrowser for help on using the repository browser.