Title Description
DescriptionGiven two floating-point numbers, please determine if the two floating-point numbers are equal. Enter a description
Input DescriptionEnter only one row with two floating-point output descriptions
Output DescriptionOutput only one row, or output yes if equal, otherwise output no. Sample input
Sample Input2.980000001 2.9800000000001 Sample Output
Sample OutputYes data range and hints
Data Size & HintWe generally consider two floating-point numbers to be equal when and when the error between them does not exceed 1e-8. Idea: Because it is a floating-point number, you need a precise comparison, you can take two floating-point number to subtract the absolute value and 1e-8 comparison, if less than equal to this exact bit, that is, the two floating-point numbers equal code as follows:
1#include <stdio.h>2#include <math.h>3 intMain ()4 {5 Doubleb;6scanf"%LF%LF",&a,&b);7 if(Fabs (A-B) <=1e-8)//Fabs is the absolute value8 {9printf"yes\n");Ten } One Else if(a!=b) printf ("no\n"); A return 0; -}
code[vs]-determining whether floating-point numbers are equal-floating-point processing-ladder Bronze