finished cls04

This commit is contained in:
2026-05-12 18:17:51 +09:00
parent 5a46adecd9
commit bddcc77361
15 changed files with 329 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
#include <stdio.h>
#include "reduce.h"
#include "utils.h"
int subFrac(int x[], int y[]) {
if (x[1] == 0 || y[1] == 0) {
return -1;
}
int l = lcm(x[1], y[1]);
int z[] = {
(x[0] * l)/x[1] - (y[0] * l)/y[1],
l
};
reduce(z);
formatNeg(z);
x[0] = z[0];
x[1] = z[1];
return 0;
}
int main(void) {
int x[2] = {0};
int y[2] = {0};
inputFrac(x);
inputFrac(y);
int ret = subFrac(x, y);
if (ret == 0) {
printFrac(x);
putchar('\n');
} else {
fprintf(stderr, "Error: detected zero div\n");
}
return 0;
}