Floating Point Number + NAN - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Floating Point Number + NAN

sonu_1984sonu_1984 Posts: 6Member




float square(float);
void main()
float a,b;
printf("ENter a Number");
printf("\nSquare of %f is %f",a,b);

float square(float x)
float y;


In the above program, I am calculating the square of float number. But sometimes the number is entered as NAN and sometimes Output is NAN. What is NAN? I am entering floating point number, then y NAN is entered?
SEE the Image attached for the OUTPUT.

228 x 159 - 2K


  • HK_MP5KPDWHK_MP5KPDW Posts: 770Member ✭✭✭

    When making any post, please make use of the preview button to make sure the code is formatted properly. Edit your post until the preview looks as clean as possible before finally clicking on the "Post Comment" button. What you've got now is not very readable and likely to make many ignore your post because it isn't worth their time to try and understand.

    When coding, try your best to make code that complies with the standard. This makes it easy for more people to copy/paste your code and help you out with running/debugging.

    As an example of non-standard coding, the <conio.h> header and the clrscr/getch functions are non-standard.

    Also, the main function returns an int according to the standard.

    NAN means "Not A Number", it is an indication that some value stored into the variable cannot be represented as a number. I compiled and ran your code (minus the non-standard <conio.h> and clrscr/getch bits) without problem getting a correct result of 9 for an input value of 3 without any NAN value being shown.

    It might also help to know what your dev environment is OS and IDE.

Sign In or Register to comment.