Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Name the statement that used to compare two float variable

+3 votes
asked Feb 12, 2023 by asish sarkar (350 points)

2 Answers

0 votes
answered Feb 12, 2023 by HOTSHOT (140 points)

Comparing floating-point values by using either the equality (==) or inequality (!=) operators is not always accurate because of rounding errors.

Compare the two float values to see if they are close in value.

float a;
float b;

if(a==b)
{
..
}
0 votes
answered Feb 13, 2023 by Peter Minarik (86,180 points)

The equals (==) operator can do that for you.

In C, you'd have the following code:

#include <stdio.h>

int main()
{
    float f1 = 3.14f;
    float f2 = 3.0f;
    if (f1 == f2)
        printf("The two floats are equal.");
    else
        printf("The two floats are different.");
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...