Commit | Line | Data |
---|---|---|
24306072 H |
1 | #include <stdio.h> |
2 | #include <math.h> | |
3 | #include <time.h> | |
4 | #define PI 3.141592653589793 | |
5 | #include <termios.h> | |
6 | #include <sys/ioctl.h> | |
7 | #include <stdlib.h> | |
8 | #include <unistd.h> | |
9 | ||
10 | int main(void) { | |
11 | //get size of terminal | |
12 | int lines = 20; | |
13 | int cols = 20; | |
14 | /*FILE *p; | |
15 | p = popen("stty size", "r"); | |
16 | fscanf(p, "%d %d", &lines, &cols); | |
17 | close((int)p);*/ | |
18 | struct winsize ws; | |
19 | if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && | |
20 | ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && | |
21 | ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || | |
22 | ws.ws_col == 0) { | |
23 | lines = 25; | |
24 | cols = 80; | |
25 | } else { | |
26 | lines = ws.ws_row; | |
27 | cols = ws.ws_col; | |
28 | } | |
29 | ||
30 | char *format; | |
31 | asprintf(&format,"%%0.%dlf\r",cols-2); | |
32 | ||
33 | ||
34 | double pi=0, i=1; | |
35 | ||
36 | while(1) { | |
37 | printf(format, pi); | |
38 | pi+=(4/i); | |
39 | i+=2; | |
40 | pi-=(4/i); | |
41 | i+=2; | |
42 | } | |
43 | //system("PAUSE"); | |
44 | //return EXIT_SUCCESS; | |
45 | } |