Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to keep 2 decimal places for integers in C language, just like int a, B and C; a= 1,b=2,c = 3; The average result is 2.00.
How to keep 2 decimal places for integers in C language, just like int a, B and C; a= 1,b=2,c = 3; The average result is 2.00.
When calculating the average value, one of A, B and C is forcibly converted to floating-point type, and two decimal places can be reserved when outputting.

For example:

printf("%.2f ",((float)a+b+c)/3);

Convert a to float, and the result of the operation is floating point, that is, you can get decimals. Use %.2f when outputting, that is, keep 2 decimal places and output floating-point numbers.