Hi,every one.I am new to C language and there I had tried a program as here and I got an output from what I had expected and hope you will help in this aspect and I have given the program as an attachment for better viewing of it.


thank you
vinaychalluru

It's better to put the code directly in your post if it's short. The problem is that floating-point values aren't always exact, so you can't reliably test for equality. The usual fix for your problem is to do a "close enough" test using the difference of the two values and a suitably small epsilon value:

#include <stdio.h>
#include <math.h>

static double floating_epsilon ( int precision )
{
  double result = 0.1;

  while ( --precision >= 0 )
    result /= 10;

  return result;
}

int main ( void )
{
  float a = 1.1;
  double b = 1.1;

  if ( fabs ( a - b ) <= floating_epsilon ( 1 ) )
    printf("Both are equal\n");
  else
    printf("Both of them are not equal\n");

  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.