pia - PI approximator - just toy
authorHarvie <tomas@mudrunka.cz>
Sun, 31 Oct 2010 18:49:37 +0000 (19:49 +0100)
committerHarvie <tomas@mudrunka.cz>
Sun, 31 Oct 2010 18:49:37 +0000 (19:49 +0100)
c/pia.c [new file with mode: 0644]

diff --git a/c/pia.c b/c/pia.c
new file mode 100644 (file)
index 0000000..3f7fc27
--- /dev/null
+++ b/c/pia.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <math.h>
+#include <time.h>
+#define PI 3.141592653589793
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(void) {
+  //get size of terminal
+  int lines = 20;
+  int cols = 20;
+  /*FILE *p;
+  p = popen("stty size", "r");
+  fscanf(p, "%d %d", &lines, &cols);
+  close((int)p);*/
+  struct winsize ws;
+  if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
+    ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
+    ioctl(STDIN_FILENO,  TIOCGWINSZ, &ws) == -1) ||
+    ws.ws_col == 0) {
+      lines = 25;
+      cols = 80;
+  } else {
+    lines = ws.ws_row;
+    cols = ws.ws_col;
+  }
+
+       char *format;
+       asprintf(&format,"%%0.%dlf\r",cols-2);
+
+
+  double pi=0, i=1;
+
+       while(1) {
+               printf(format, pi);
+               pi+=(4/i);
+               i+=2;
+               pi-=(4/i);
+               i+=2;
+       }
+  //system("PAUSE");
+  //return EXIT_SUCCESS;
+}
This page took 0.111652 seconds and 4 git commands to generate.