Minggu, Juni 22, 2014

Different of %e, %f, and %g For float Variable On C Programming Language

There are three printf code can be used for float variable on C programming language, are %e, %f and %g. Example on a program syntax is defined value of a float variable is 7,1234
  • If used %e code, then when program is run will be show 7,123400e+000 (it means 7,123400 x 10^0)
  • If used %f code, then when program is run will be show 7,123400
  • If used %g code, then when program is run will be show 7,1234
Example of its program as follows:

main()
{
  float num = 7.1234;
  printf("If used %ce code, then its screenshow is: %e", 37,num);
  printf("\nIf used %cf code, then its screenshow is: %f", 37,num);
  printf("\nIf used %cg code, then its screenshow is: %g", 37,num);
  getch();
}

0 komentar: