diff options
author | joerg <joerg@FreeBSD.org> | 1997-03-23 18:51:21 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1997-03-23 18:51:21 +0000 |
commit | 1b9d0472b72177a604d3c5dd26d25eec00049bd2 (patch) | |
tree | 1409de2219944c7c90248988b70ac693cf71206d /contrib/top/prime.c | |
download | FreeBSD-src-1b9d0472b72177a604d3c5dd26d25eec00049bd2.zip FreeBSD-src-1b9d0472b72177a604d3c5dd26d25eec00049bd2.tar.gz |
This is the long-awaited import of top into the base system (actually,
the src/contrib/top part right now). This tools is simply too system-
dependant to maintain it in the ports collection.
Diffstat (limited to 'contrib/top/prime.c')
-rw-r--r-- | contrib/top/prime.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/contrib/top/prime.c b/contrib/top/prime.c new file mode 100644 index 0000000..319d0b6 --- /dev/null +++ b/contrib/top/prime.c @@ -0,0 +1,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); + } + } +} |