EmbLogic's Blog

I have problem with the code

double d;

int i;

float f ;

long l;

i=l=f=d=100;

printf(“%.8g\t”,(double)i);

The output comes 33 instead of 33.33333

Why and what is the significance of %.8g

One Response to

  1. i=l=f=d=100/3
    the o/p is 33 because 100/3 is an integer division (by default)
    for 33.3333, the division should be 100./3

    %g represents float value
    .8 is used to round the ans till 8 places of decimal (no significance in this quest.)

Leave a 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>