完整的C程序:
#include "stdio.h"
typedef struct
{
int numerator;
int denominator;
} Fraction;
int GCD(int a,int b);
int LCM(int a,int b);
Fraction Add(Fraction f1, Fraction f2);
void main()
{
Fraction f1, f2, f3;
f1.numerator = 1;
f1.denominator = 3;
f2.numerator = 1;
f2.denominator = 6;
f3 = Add(f1, f2);
printf("%d/%d + %d/%d = %d/%d\n", f1.numerator, f1.denominator, f2.numerator, f2.denominator, f3.numerator, f3.denominator);
}
Fraction Add(Fraction f1, Fraction f2)
{
Fraction retValue;
int lcm = LCM(f1.denominator, f2.denominator);
int gcd;
retValue.denominator = lcm;
retValue.numerator = f1.numerator * lcm / f1.denominator + f2.numera