#include #include #include #include // pnut.c - lrb // gcc pnut.c -lm -o pnut /* The Prime Number Theorem says that n divided by the number of primes less than n approaches the natural logarithm of n. This program counts the number of primes less than n and displays this ratio and the natural logarithm of n. */ int isprime(int number) { if (number<=1) return 0; int i; for (i=2;i*i<=number;++i) { if (number%i==0) return 0; } return 1; } void usage() { printf("\npnut.c - 2/3/20"); printf("\n\nUsage: pnut -n number where n < 10000000\n"); exit(1); } int main(int argc,char *argv[]) { if (argc!=3) usage(); unsigned int i,n,ctr=1; for (i=1;i10000000) {printf("\nyour number is too big\n");exit(0);} for (i=3;i<=n;i+=2) { ctr+=isprime(i); } printf("\nn / # primes < n = %d / %d = %3.7f\n",n,ctr,1.0*n/ctr); printf("\nln(%d) = %3.7f\n",n,log(n)); return 0; }