Saturday, 6 February 2016

What are the differences between %f, %e and %g format specifiers in C language? Explain with examples in which these format specifiers are emplyed.

  1. %f prints the corresponding number as a decimal floating point number (e.g. 321.65),
  2.  %e prints the number in scientific notation (e.g. 3.2165e+2), 
  3. %g prints the number in the shortest of these two representations (using the same number, the decimal floating point is shorter and hence 321.65 would be printed.  An example where %g would print the scientific notation is when the number is 6000000000.  In scientific notation, this would 6e+9 which is shorter and hence, 6e+9 would be printed.)
  4. The only difference between the lower case %e, %g and the upper case versions %E, %G is that printing scientific notation will use an upper case E instead of a lower case e to indicate the exponent.  E.g.  %E produces 3.2165E+2 when %e produces 3.2165e+2.

No comments :

Post a Comment