/*******************************************/ /* Program liczy liczbë pi metodâ trapezów */ /* Napisane dla Magazynu Amiga */ /* 1995 by BsZ */ /*******************************************/ #include #include #include float f(float x) { return((float)(1.0/(1+x*x))); } main(int argc, char *argv[]) { long int loop; float N,pi=0; long int t0,t; if(argc!=2) { printf("Nie podaîeô podziaîu!\n"); exit(0); } N=(float)atol(argv[1]); time(&t0); for(loop=1;loop<=N;loop++) pi+=f( (float)((loop-1)/N) ) + f( (float)(loop/N) ); pi*=2.0/N; time(&t); printf("Wyliczona wartoôê pi: %f\nCzas obliczeï: %lds\n",pi,t-t0); }