#include <stdio.h>
typedef struct
{
int numerator;
int denominator;
}RATIONAL;
void reduce(RATIONAL *r1,RATIONAL *r2)
{
int a,b,rem;
if(r1->numerator > r1->denominator)
{
b=r1->denominator;
a=r1->numerator;
}
else{
a=r1->denominator;
b=r1->numerator;
}
while(b!=0)
{
rem=a%b;
a=b;
b=rem;
}
r2->numerator/=a;
r2->denominator/=a;
}
int main()
{
RATIONAL r1={24,12};
RATIONAL red;
reduce(&r1,&red);
printf("%i/%i",red.numerator,red.denominator);
}
我得到的答案很模糊,根本与所需的输出不匹配(对于参考输出= 350066/4)。我不明白为什么会这样。请告诉我这段代码有什么问题。 谢谢!