次のテスト用のmainを含む関数群を必ず使用すること
#include <stdio.h>
/*fraction_t型の定義*/
typedef struct {
int numerator; /*分子*/
int denominator; /*分母*/
} fraction_t;
/*式と答えを表示する a ope b = c*/
void printcheckfraction(fraction_t a, char ope, fraction_t b, fraction_t c)
{
printf("(%d/%d) %c (%d/%d) = (%d/%d)\n",
a.numerator,a.denominator, ope,
b.numerator,b.denominator,
c.numerator,c.denominator
);
}
/*四則演算のチェック用関数 a, b にて四則演算を行い,式を表示する*/
void checkfraction(fraction_t a, fraction_t b)
{
fraction_t c;
c=addFraction(a,b);
printcheckfraction(a,'+',b,c);
c=subtractFraction(a,b);
printcheckfraction(a,'-',b,c);
c=subtractFraction(b,a);
printcheckfraction(b,'-',a,c);
c=multiplyFraction(a,b);
printcheckfraction(a,'*',b,c);
c=divideFraction(a,b);
printcheckfraction(a,'/',b,c);
c=divideFraction(b,a);
printcheckfraction(b,'/',a,c);
printf("\n");
}
int main()
{
fraction_t a={1,6};
fraction_t b={1,3};
fraction_t am={-1,6};
fraction_t bm={-1,3};
fraction_t c={3,4};
fraction_t d={16,3};
fraction_t cm={-3,4};
fraction_t dm={-16,3};
checkfraction(a,b);
checkfraction(a,bm);
checkfraction(am,b);
checkfraction(am,bm);
checkfraction(c,d);
checkfraction(c,dm);
checkfraction(cm,d);
checkfraction(cm,dm);
return 0;
}
以下の実行結果が得られたら正解(自分で1つずつ確かめてから課題提出のこと)
/*
(1/6) + (1/3) = (1/2)
(1/6) - (1/3) = (-1/6)
(1/3) - (1/6) = (1/6)
(1/6) * (1/3) = (1/18)
(1/6) / (1/3) = (1/2)
(1/3) / (1/6) = (2/1)
(1/6) + (-1/3) = (-1/6)
(1/6) - (-1/3) = (1/2)
(-1/3) - (1/6) = (-1/2)
(1/6) * (-1/3) = (-1/18)
(1/6) / (-1/3) = (-1/2)
(-1/3) / (1/6) = (-2/1)
(-1/6) + (1/3) = (1/6)
(-1/6) - (1/3) = (-1/2)
(1/3) - (-1/6) = (1/2)
(-1/6) * (1/3) = (-1/18)
(-1/6) / (1/3) = (-1/2)
(1/3) / (-1/6) = (-2/1)
(-1/6) + (-1/3) = (-1/2)
(-1/6) - (-1/3) = (1/6)
(-1/3) - (-1/6) = (-1/6)
(-1/6) * (-1/3) = (1/18)
(-1/6) / (-1/3) = (1/2)
(-1/3) / (-1/6) = (2/1)
(3/4) + (16/3) = (73/12)
(3/4) - (16/3) = (-55/12)
(16/3) - (3/4) = (55/12)
(3/4) * (16/3) = (4/1)
(3/4) / (16/3) = (9/64)
(16/3) / (3/4) = (64/9)
(3/4) + (-16/3) = (-55/12)
(3/4) - (-16/3) = (73/12)
(-16/3) - (3/4) = (-73/12)
(3/4) * (-16/3) = (-4/1)
(3/4) / (-16/3) = (-9/64)
(-16/3) / (3/4) = (-64/9)
(-3/4) + (16/3) = (55/12)
(-3/4) - (16/3) = (-73/12)
(16/3) - (-3/4) = (73/12)
(-3/4) * (16/3) = (-4/1)
(-3/4) / (16/3) = (-9/64)
(16/3) / (-3/4) = (-64/9)
(-3/4) + (-16/3) = (-73/12)
(-3/4) - (-16/3) = (55/12)
(-16/3) - (-3/4) = (-55/12)
(-3/4) * (-16/3) = (4/1)
(-3/4) / (-16/3) = (9/64)
(-16/3) / (-3/4) = (64/9)*/