/*********************************************************************/
/* Koudelka's Pi Taylor Series Calculator                            */
/*                                                                   */
/* - to compile, type "eval $(tail -1 kt.c)"                         */
/* - for output, compile with -DUSE_STDIO                            */
/*********************************************************************/

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
  register double sum = 0.0;
  register int i, max;
  
  max = (argc > 1) ? atoi(argv[1]) : 10000000;

  for (i = 0; i < max; i++) {
    sum += ((i & 1) ? -1.0 : 1.0) / (2 * i + 1);

#ifdef USE_STDIO
    if (i % 100 == 0)
      printf("%.02f\r", 4 * sum);
#endif /* USE_STDIO */
  }
  
#ifdef USE_STDIO
  /* make sure the line doesn't get mangled on exit, and flush
   * line-buffered standard output */
  printf("\n");
#endif /* USE_STDIO */

  return EXIT_SUCCESS;
}

/* compile line
cc -o kto -W -Wall -pedantic -O2 kt.c && cc -o kt -W -Wall -pedantic kt.c # */

