代码:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
int up1,down1,up2,down2;
do{
printf("Enter two fractions seperated by a plus sign:");
scanf("%d/%d+%d/%d",&up1,&down1,&up2,&down2);
int down3=down1\*down2;
int up3=up1\*down2+up2\*down1;
int small=(up3<down3)?up3:down3;
int gcd;
for(;small>;small--){
if(up3%small== && down3%small==)
{
gcd=small;
break;
}
}
printf("The sum is %d/%d\\n",up3/gcd,down3/gcd);
}while(up1!=);
return ;
}
代码:
Enter two fractions seperated by a plus sign:/+/
The sum is /
Enter two fractions seperated by a plus sign:/+/
The sum is /
Enter two fractions seperated by a plus sign:/+/
The sum is /
Enter two fractions seperated by a plus sign:/+/
The sum is /
Enter two fractions seperated by a plus sign:/+/
The sum is /
--2020年6月9日--
手机扫一扫
移动阅读更方便
你可能感兴趣的文章