EmbLogic's Blog

Question No.15 of Assignment-1

int main()

{

float a,

a = 2.0e20;

printf(“%f”,a);

}

Here looking at the program we expect that the output should be like 200..( 0 for 20 times).

but to our astonishment we are getting the output as 200000004008175468544.

Can anyone please tell me the reason behind such an output.?

2 Responses to Question No.15 of Assignment-1

  1. mandeeshc says:

    2.0e20 is out of range for float, thus you are getting such an output. Infact, any this > e10 in float will give an unexpected output. Try it with double, it’ll work.

  2. float work anly on 6 decimals so thats why it gives u wrong ans

Leave a Reply to Kuldeep Dhanotia Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>