1. Input and output of floating point constants
Sample code: #include<stdio.h> intmain() { double a; double b; scanf("%lf",&a); scanf("%lf",&b); printf(" %f divided by %f is %f ",a,b,a/b); return 0; }
Run the screenshot:
Knowledge points:
1. When the double type is output by the printf function, use " %f " for conversion instructions.
2. The format string " %lf " needs to be used when the double type is assigned by the scanf function. Note that lf is not f !
3. The conversion description of double input and output is different from the format string ! ! This is not the same as an integer ! !
2. Forced type conversion
Sample code:
#include<stdio.h>
intmain()
{
int a;
int b;
scanf("%d",&a);
scanf("%d",&b);
printf("The average of %d and %d is %f \n",a,b, (double) (a+b)/2);
return 0;
}
Knowledge points:
The mandatory type conversion in C language is basically the same as that in C++.