/home/toolbox/public_html/solutions/8/834/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 #define MAX_LINE 257
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2026-09-11
21 * Purpose: fun
22 * Problem: 834 - Continued Fraction
23 */
24
25 /*
26 * This template reads lines of data at a time until end of file.
27 */
28
29 #define MAX_DEPTH 64
30
31 int x; /* starting numerator */
32 int y; /* starting denominator */
33 int ans[MAX_DEPTH]; /* save all the values */
34 int cnt;
35 int first;
36
37 void init()
38 {
39 /* FUNCTION init */
40 } /* FUNCTION init */
41
42 void dump()
43 {
44 /* FUNCTION dump */
45 } /* FUNCTION dump */
46
47 int getInput()
48 {
49 /* FUNCTION getInput */
50 int dataReadFlag;
51
52 dataReadFlag = (2 == scanf(" %d %d ", &x, &y));
53 return (dataReadFlag);
54 } /* FUNCTION getInput */
55
56 void process()
57 {
58 /* FUNCTION process */
59 int tmp;
60 char sep = ';';
61 int i = 1;
62
63 cnt = 0;
64 first = x / y;
65 x = x % y;
66 while (y > 0)
67 {
68 /* compute next fraction digit */
69 DEBUG printf("(x=%d) (y=%d) (cnt=%d) \n", x, y, cnt);
70 ans[cnt] = x / y;
71 cnt++;
72 tmp = x;
73 x = y;
74 y = tmp % y;
75 } /* compute next fraction digit */
76 /* not deal with output */
77 printf("[%d", first);
78 while (i < cnt)
79 {
80 /* loop for each digit */
81 printf("%c", sep);
82 sep = ',';
83 printf("%d", ans[i]);
84 i++;
85 } /* loop for each digit */
86 printf("]\n");
87
88 } /* FUNCTION process */
89
90 int main()
91 {
92 /* main */
93 int moreToDo;
94
95 init();
96 moreToDo = getInput();
97 while (moreToDo)
98 {
99 /* while */
100 DEBUG printf("%d %d\n", x, y);
101 process();
102 moreToDo = getInput();
103 } /* while */
104
105 return EXIT_SUCCESS;
106 } /* main */
107