%g%g represents the decimal format of the answer, depending upon whose length is smaller, comparing between %e and %f.
Also removes succeeding zeros.
Example 1:
123.45, it will print it as 123.45
%f : 123.450000 & %e : 1.234500e+02
After removing succeeding zeros
%f : 123.45 & %e : 1.2345e+02
%f gives shorted result. So, %g prints 123.45
Example 2:
123.45 * 10^8, it will print it as 1.2345e+10
%f : 12345000000.000000 & %e : 1.234500e+10
After removing succeeding zeros
%f : 12345000000 & %e : 1.2345e+10
%e gives shorted result. So, %g prints 1.2345e+10