Printing floating-point numbers with various conversion specifiers of the printf() C function
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: none
To do: Printing floating-point numbers with various conversion specifiers of the printf() C function
To show: How to print floating-point with various conversion specifiers of the printf() C function
// Printing floating-point numbers with various floating-point conversion specifiers
#include <stdio.h>
int main(void)
{
printf("Printing floating-point numbers with\n");
printf("floating-point conversion specifiers.\n");
printf("Compare the output with source code\n\n");
printf("1. %%e = %e\n", 1234567.89);
printf("2. %%e = %e\n", +1234567.89);
printf("3. %%e = %e\n", -1234567.89);
printf("4. %%E = %E\n", 1234567.89);
printf("5. %%f = %f\n", 1234567.89);
printf("6. %%g = %g\n", 1234567.89);
printf("7. %%G = %G\n", 1234567.89);
return 0;
}
Output example:
Printing floating-point numbers with
floating-point conversion specifiers.
Compare the output with source code
1. %e = 1.234568e+006
2. %e = 1.234568e+006
3. %e = -1.234568e+006
4. %E = 1.234568E+006
5. %f = 1234567.890000
6. %g = 1.23457e+006
7. %G = 1.23457E+006
Press any key to continue . . .