Files
C_code/翁凯C语言/3/约分最简分式.c

32 lines
470 B
C

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int gcd(int x, int y) // 求最大公约数
{
int c;
while (y > 0)
{
c = x % y;
x = y;
y = c;
}
return x;
}
int main()
{
int m;
int n;
printf("请输入分式m/n:");
scanf("%d/%d", &m, &n);
int a, b;
int num_gcd = gcd(m, n);
a = m / num_gcd;
b = n / num_gcd;
printf("%d/%d的化简分式是%d/%d\n", m, n, a, b);
return 0;
}