/home/toolbox/public_html/solutions/3/324/example.c
1 #include <stdio.h>
2 #define DEBUG1 (1 != 1)
3
4 #include "LargeNumber.c"
5
6 int main ()
7 {
8 /* begin FUNCTION main */
9 int i;
10 LARGE_NUMBER_STRUCT a;
11 LARGE_NUMBER_STRUCT b;
12 LARGE_NUMBER_STRUCT c;
13 int res;
14 long int ii;
15 char num[1000];
16 char tmp[1000];
17
18 ii = 123456789;
19 if (DEBUG1) printf ("A\n");
20 res = LNicnvrt(ii, &a);
21 printf("------- Display Test ----------\n");
22 LNarr2strExp(&a, num);
23 printf("LNarr2strExp(a)=%s\n",num);
24 LNarr2strInt(&a, num);
25 printf("LNarr2strInt(a)=%s\n",num);
26 LNln2strFloat(&a, num);
27 printf("LNln2strFloat(a)=%s\n",num);
28 LNprint(&a);
29 printf("-------------------------------\n");
30
31 printf("------- Multiply Test ---------\n");
32 LNicnvrt(123, &a);
33 LNicnvrt(12, &b);
34 LNmultiply(&a, &b, &c);
35 LNarr2strInt(&a, num);
36 printf("a(%s) * ", num);
37 LNarr2strInt(&b, num);
38 printf("b(%s) ", num);
39 LNarr2strInt(&c, num);
40 printf(" = c(%s)\n", num);
41 printf("\n");
42
43 printf("-------------------------------\n");
44
45 printf("------- Divide Test ---------\n");
46 LNicnvrt(1224, &a);
47 LNdivide(&a, 12, &c);
48 LNarr2strInt(&a, num);
49 printf("a(%s) / 12 ", num);
50 LNarr2strExp(&c, num);
51 printf(" = c(%s)\n", num);
52 printf("\n");
53
54 LNicnvrt(12, &a);
55 LNdivide(&a, 12, &c);
56 LNarr2strInt(&a, num);
57 printf("a(%s) / 12 ", num);
58 LNarr2strExp(&c, num);
59 printf(" = c(%s)\n", num);
60 printf("\n");
61
62 LNicnvrt(1, &a);
63 LNdivide(&a, 1, &c);
64 LNarr2strInt(&a, num);
65 printf("a(%s) / 1 ", num);
66 LNarr2strExp(&c, num);
67 printf(" = c(%s)\n", num);
68 printf("\n");
69
70 LNicnvrt(1, &a);
71 LNdivide(&a, 12, &c);
72 LNarr2strInt(&a, num);
73 printf("a(%s) / 12 ", num);
74 LNarr2strExp(&c, num);
75 printf(" = c(%s)\n", num);
76 printf("\n");
77
78 LNicnvrt(1, &a);
79 LNdivide(&a, 125, &c);
80 LNarr2strInt(&a, num);
81 printf("a(%s) / 125 ", num);
82 LNarr2strExp(&c, num);
83 printf(" = c(%s)\n", num);
84
85 for (i=100000; i >= 10; i = i / 10)
86 {
87 LNstr2arr("1111.111111111", &a);
88 LNdivide(&a, i, &c);
89 LNarr2strInt(&a, num);
90 printf("a(%s) / %d ", num, i);
91 LNarr2strExp(&c, num);
92 printf(" = c(%s)\n", num);
93 }
94
95 sprintf(tmp, "0.0000000000000000000000000000000000000000000000000000000000000000000000001111111111111");
96 LNstr2arr(tmp, &a);
97 LNdivide(&a, 10, &c);
98 LNarr2strInt(&a, num);
99 printf("a(%s) / 10 ", num);
100 LNarr2strExp(&c, num);
101 printf(" = c(%s)\n", num);
102
103 sprintf(tmp, "30765988567369.349386373638586534058340853486734086334739573957397534757357345973497375734573453957");
104 LNstr2arr(tmp, &a);
105 LNdivide(&a, 123456789, &c);
106 LNarr2strInt(&a, num);
107 printf("a(%s) / 123456789 ", num);
108 LNarr2strExp(&c, num);
109 printf(" = c(%s)\n", num);
110
111 printf("\n");
112
113 printf("-------------------------------\n");
114 LNicnvrt(123, &a);
115 if (DEBUG1) printf ("B\n");
116 printf("\n");
117
118 printf("-------------------------------\n");
119 LNicnvrt(123, &a);
120 if (DEBUG1) printf ("B\n");
121 res = LNcopy(&a,&b);
122 b.array[b.exponent] = 3;
123 if (DEBUG1) printf ("C\n");
124 LNprint(&a);
125 printf("%d - %d\n",a.exponent,a.digitCount);
126 LNprint(&b);
127 printf("%d - %d\n",b.exponent,b.digitCount);
128 if (DEBUG1) printf ("D\n");
129 a.array[0] = 2;
130 LNarr2strExp(&a, num);
131 printf("arr2str: [%s]\n", num);
132
133 a.array[0] = 3;
134 LNarr2strExp(&a, num);
135 printf("ln2strExp: [%s]\n", num);
136
137 a.array[0] = 4;
138 LNarr2strInt(&a, num);
139 printf("ln2strInt: [%s]\n", num);
140
141 a.array[0] = 5;
142 a.exponent = 3;
143 LNarr2strInt(&a, num);
144 printf("ln2strInt: [%s]\n", num);
145
146 a.array[0] = 6;
147 a.exponent = 15;
148 LNarr2strInt(&a, num);
149 printf("ln2strInt: [%s]\n", num);
150
151 a.array[0] = 7;
152 a.exponent = 7;
153 LNln2strFloat(&a, num);
154 printf("ln2strFloat: [%s]\n", num);
155
156 LNadd(&a, &b, &c);
157 LNarr2strExp(&a, num);
158 printf("[%s] + ", num);
159 LNarr2strExp(&b, num);
160 printf("[%s] = ", num);
161 LNarr2strExp(&c, num);
162 printf("[%s]\n", num);
163
164 LNsubtract(&a, &b, &c);
165 LNarr2strExp(&a, num);
166 printf("[%s] - ", num);
167 LNarr2strExp(&b, num);
168 printf("[%s] = ", num);
169 LNarr2strExp(&c, num);
170 printf("[%s]\n", num);
171
172 LNsubtract(&b, &a, &c);
173 LNarr2strExp(&b, num);
174 printf("[%s] - ", num);
175 LNarr2strExp(&a, num);
176 printf("[%s] = ", num);
177 LNarr2strExp(&c, num);
178 printf("[%s]\n", num);
179
180 } /* end FUNCTION main */
181