C011:分数相加
2024-10-06 13:28:44
代码:
#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日--
最新文章
- html5 自定义标签取值
- 使用jquery-qrcode生成二维码
- tomcat 7/8 启动非常慢的解决方法
- php示例代码之使用mysql_fetch_object函数
- primefaces 上传文件尺寸受限制 Connection terminated as request was larger than
- Redis 的 5 个常见使用场景
- 值得学习的C语言开源项目
- Python之Flask Web开发
- js密码强度
- Codeforces Beta Round #51 B. Smallest number dfs
- 基于内嵌Tomcat的应用开发
- delphi xe5 android sample 中的 SimpleList 是怎样绑定的
- clone Control event handlers at run time
- 【Zookeeper】3.4.9 基本配置
- 新手了解.Nat
- 用Maven快速生成带有依赖的可执行jar包
- Python中数学函数
- spring boot 2.0 neo4j 使用
- html5dom2
- NIO 之 ByteBuffer