Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to use floating-point A, B and C in C language?
How to use floating-point A, B and C in C language?
1. Open C-Free and create a new file.

2. Enter the following: (Take division as an example)

# include & ltstdio.h & gt?

Master ()

{

Floating a, b, c; ?

Printf ("Please enter dividend:");

scanf("%f ",& ampa);

Printf ("\ nPlease enter a divisor:");

scanf("%f ",& ampb); ?

c = a/b; ?

printf(" \ n % f \u% f = % f \ n ",a,b,c); ?

}?

3. Press F5 to run and get the result.

4. Floating points A, B and C; It means setting three floating-point variables, named a, b and c respectively, which are different from integer variables (int a, b, c; ) and string variables (char a, b, c; ), floating-point variables are numeric variables that can take decimals. ?

5、scanf("%f ",& ampa); This means that the number you enter is stored in a table with 6 decimal places.

6、c = a/b; It is an assignment statement, which means that the value of A divided by B is given to C. In the four operations, the addition operator is+,the subtraction is-,the multiplication is *, and the division is/.

7. If you only want to keep three decimal places, you can add .3 in the middle of %f, that is, printf ("\ n% .3f \% .3f =% .3f \ n ",a, b, c).

8. Of course, %.3f is the same as %d, and the preceding %f corresponds to the following variables one by one.