prime.c revision 24139
1219820Sjeff/* 2219820Sjeff * Prime number generator. It prints on stdout the next prime number 3219820Sjeff * higher than the number specified as argv[1]. 4219820Sjeff */ 5219820Sjeff 6219820Sjeff#include <math.h> 7219820Sjeff 8219820Sjeffmain(argc, argv) 9219820Sjeff 10219820Sjeffint argc; 11219820Sjeffchar *argv[]; 12219820Sjeff 13219820Sjeff{ 14219820Sjeff double i, j; 15219820Sjeff int f; 16219820Sjeff 17219820Sjeff if (argc < 2) 18219820Sjeff { 19219820Sjeff exit(1); 20219820Sjeff } 21219820Sjeff 22219820Sjeff i = atoi(argv[1]); 23219820Sjeff while (i++) 24219820Sjeff { 25219820Sjeff f=1; 26219820Sjeff for (j=2; j<i; j++) 27219820Sjeff { 28219820Sjeff if ((i/j)==floor(i/j)) 29219820Sjeff { 30219820Sjeff f=0; 31219820Sjeff break; 32219820Sjeff } 33219820Sjeff } 34 if (f) 35 { 36 printf("%.0f\n", i); 37 exit(0); 38 } 39 } 40} 41