training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

getpg.c (388B)


      1 /*
      2  * Esercizio 4.26
      3  * pi = 4 - (4 / 3) + (4 / 5) - (4 / 7) + (4 / 9) - (4 / 11) + ...
      4 */
      5 
      6 #include <stdio.h>
      7 
      8 int main()
      9 {
     10    double pi = 4.0;
     11    int i, t = 1;
     12 
     13    printf("PI VALUE\t(+/-) 4 / X\tTERMS\n");
     14    for (i = 3; pi > 3.141593; ++t, i += 2) {
     15       pi -= 4.0 / i;
     16       i += 2;
     17       pi += 4.0 / i;
     18    }
     19 
     20    printf("%f\t4 / %d\t%d\n", pi, i, t);
     21 
     22    return 0;
     23 } /* E0F main */
     24