From 24306072441f3e4c10d7a40e416336f5b64a89db Mon Sep 17 00:00:00 2001 From: Harvie Date: Sun, 31 Oct 2010 19:49:37 +0100 Subject: [PATCH] pia - PI approximator - just toy --- c/pia.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 c/pia.c diff --git a/c/pia.c b/c/pia.c new file mode 100644 index 0000000..3f7fc27 --- /dev/null +++ b/c/pia.c @@ -0,0 +1,45 @@ +#include +#include +#include +#define PI 3.141592653589793 +#include +#include +#include +#include + +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; +} -- 2.30.2