From: Harvie Date: Sun, 31 Oct 2010 18:49:37 +0000 (+0100) Subject: pia - PI approximator - just toy X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=24306072441f3e4c10d7a40e416336f5b64a89db;p=mirrors%2FPrograms.git pia - PI approximator - just toy --- 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; +}