1203 判断浮点数是否相等
时间限制: 1 s
空间限制: 128000 KB
题目等级 : 青铜 Bronze
题目描述 Description
给出两个浮点数,请你判断这两个浮点数是否相等
输入描述 Input Description
输入仅一行,包含两个浮点数
输出描述 Output Description
输出仅一行,如果相等则输出yes,否则输出no。
样例输入 Sample Input
2.980000001 2.9800000000001
样例输出 Sample Output
yes
数据范围及提示 Data Size & Hint
我们一般认为两个浮点数相等,当且当他们之间的误差不超过1e-8。
这个题在OpenJudge上也有,不是很难的题,就是单纯的比较,只要学了if应该都能过·······
#include<cstdio> #include<cmath> using namespace std; int a[10000000]; int abs(int x) { if(x<0) return -x; else return x; } int main() { double n,m; scanf("%lf%lf",&n,&m); if(abs(m-n)<=1e-8) printf("yes"); else printf("no"); return 0; }