作者在 2015-10-22 20:12:33 发布以下内容
#include<stdio.h>
int main() {
int a, b, c, m, n, f, h, gcd;
scanf("%d %d", &a, &b);
if (0 <= a && a <= 10000, 0 <= b && b <= 10000) {
m = a;
n = b;
f = m/gcd;
h = n/gcd;
if (a < b)
a ^= b ^= a ^= b;
while (b != 0) {
c = a%b;
a = b;
b = c;
}
gcd = a;
if (n == 0) {
printf("Error\n");
} else {
if (m == 0) {
printf("Zero\n");
} else {
printf("%d/%d==>%d/%d\n", m/n, f/h);
}
}
}
return 0;
}
int main() {
int a, b, c, m, n, f, h, gcd;
scanf("%d %d", &a, &b);
if (0 <= a && a <= 10000, 0 <= b && b <= 10000) {
m = a;
n = b;
f = m/gcd;
h = n/gcd;
if (a < b)
a ^= b ^= a ^= b;
while (b != 0) {
c = a%b;
a = b;
b = c;
}
gcd = a;
if (n == 0) {
printf("Error\n");
} else {
if (m == 0) {
printf("Zero\n");
} else {
printf("%d/%d==>%d/%d\n", m/n, f/h);
}
}
}
return 0;
}
出现问题:
改正版
#include<stdio.h>
int main() {
int a, b, c, m, n;
scanf("%d %d", &a, &b);
m = a;
n = b;
while (b != 0) {
c = a%b;
a = b;
b = c;
}
if (n == 0) {
printf("Error\n");
} else {
if (m == 0) {
printf("Zero\n");
} else {
printf("%d/%d==>%d/%d\n", m, n, m/a, n/a);
}
}
return 0;
}