定义一结构体数组表示分数,并求两个分数相加之和
2023-07-06
解: #include
#include
struct fenshu
int fz;
int fm;
;
main()
int I;
struct fenshu f1,f2,result;
printf(“input f1.fz:”);
scanf(“%d”,&f1.fz);
printf(“input f1.fm:”);
scanf(“%d”,&f1.fm);
printf(“input f2.fz:”);
scanf(“input f2.fz);
printf(“input f2.fm:”);
scanf(“%d”,&f2.fm);
result.fm=f1.fm*f2.fm;
result.fz=f1.fz*f2.fm+f1.fm*f2.fz;
I=result.fz;
While((result.fz%i)||(result.fm%i))
i–;
result.fm=result.fm/i;
result.fz=result.fz/i;
printf(“result.fz is:%d”,result.fz);
printf(“result.fm is:%d”,result.fm);