Testing Relational Operators with float point numbers - C Operator

C examples for Operator:Relational Operator

Introduction

Operator Meaning
<Is less than
<= Is less than or equal to
== Is equal to
>= Is greater than or equal to
>Is greater than
!= Is not equal to

floating-point comparisons

Demo Code

#include <math.h>
#include <stdio.h>
int main(void)
{
    const double ANSWER = 3.14159;
    double response;
    //from  w w w . j a  v  a2 s  . com
    printf("What is the value of pi?\n");
    scanf("%lf", &response);
    while (fabs(response - ANSWER) > 0.0001)
    {
        printf("Try again!\n");
        scanf("%lf", &response);
    }
    printf("Close enough!\n");
    
    return 0;
}

Result


Related Tutorials