Reading using scanf()/scanf_s() and writing using printf() C function for floating-point numbers
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: Reading using scanf()/scanf_s() from standard input and writing using printf() to standard output, C function for floating-point numbers
To show: How to read from standard input and write to standard output the floating-point numbers using scanf()/scanf_s() and printf() respectively
// Reading and writing floating-point numbers
#include <stdio.h>
int main(void)
{
float a, b, c;
printf(" Reading floating-point numbers\n");
printf("Compare the output with the source code.\n");
printf("----------------------------------------\n\n");
printf("Enter three floating-point numbers, separated by space: \n");
/* scanf("%e%f%g", &a, &b, &c); */
/* read three float type inputs */
scanf_s("%e%f%g", &a, &b, &c);
printf("Here are the numbers entered in plain\n");
printf("floating-point notation:\n");
printf("%f %f %f\n", a, b, c);
return 0;
}
Output example:
Reading floating-point numbers
Compare the output with the source code.
----------------------------------------
Enter three floating-point numbers, separated by space:
10.5 33.4 34.1
Here are the numbers entered in plain
floating-point notation:
10.500000 33.400002 34.099998
Press any key to continue . . .