Posted in 面试题 onJune 11, 2013
解: #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);
}
#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);
}
定义一结构体数组表示分数,并求两个分数相加之和
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@