C++编程问题,有理数的,有没有大神帮我看看怎么做,我想学一下QAQ,求主函数的

2024-12-28 00:28:02
推荐回答(1个)
回答1:

int main(void)
{
    Rational num1,num2,sum;
    char ch;
    cout<<"请按照\"a1/b1 a2/b2\"的格式输入两个有理数:";
    cin>>num1.n>>ch>>num1.d>>num2.n>>ch>>num2.d;
    sum.n=num1.n*num2.d+num2.n*num1.d;
    sum.d=num1.d*num2.d;
    int tmp=gcd(sum.n,sum.d);
    sum.n/=tmp;
    sum.d/=tmp;
    cout<    return 0;
}