code[vs]-determining whether floating-point numbers are equal-floating-point processing-ladder Bronze

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.