怎么又报错啊


私信TA

用户名:uq_89563935268

访问量:3512

签 名:

等  级
排  名 722
经  验 3736
参赛次数 0
文章发表 14
年  龄 0
在职情况 学生
学  校 江西中医药大学
专  业 计算机

  自我简介:

TA的其他文章

解题思路:

注意事项:找分母的最小公倍数,求分子分母最大公约数。

参考代码:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <stdio.h>

int main()

{

    int m,n,i,j,h,t,x,y,tem1,tem2,temn,mcc,aa,bb,cc,gcd,x1,y1,z,z1;

    char c;

    int a[10];

    int b[10];

    scanf("%d",&n);

    if(n==1)

    {

      scanf("%d%c%d",&x1,&c,&y1);

        z=x1;z1=y1;

        if(z<z1)

        {

            j=z;

            z=z1;

            z1=j;

        }

        while(z!=0)

        {

          h=z;

          z=z1%z;

          z1=h;

        }

        printf("%d%c%d\n",x1/z1,c,y1/z1);

    }

   else{  for(i=0;i<n;i++)

     scanf("%d%c%d",&a[i],&c,&b[i]);

    for(i=0;i<n-1;i++)

    {

        m=b[i];

        t=b[i+1];

        while(m!=0)

        {

            x=m;

            m=t%m;

            t=x;

        }

        y=t;

        tem1=b[i]/y;

        tem2=b[i+1]/y;

        mcc=tem1*tem2*y;

        temn=a[i]*tem2+a[i+1]*tem1;

        aa=mcc;bb=temn;

        while(aa!=0)

        {

            cc=aa;

            aa=bb%aa;

            bb=cc;

        }

        gcd=bb;

        mcc/=gcd;

        temn/=gcd;

        a[i+1]=temn;

        b[i+1]=mcc;

    }

    if(b[n-1]>1)

        printf("%d%c%d\n",a[n-1],c,b[n-1]);

    else

        printf("%d\n",a[n-1]);}

    return 0;

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区