0
Follow
0
View

Let me explain. Why not 15

zg9954 注册会员
2023-02-26 19:28

C doesn't have a way to print numbers.

  • printf prototype: int printf(const char *format,...) ;
  • printf call format: printf("< Format string >" , < Parameter scale >) ;

daitingting0123 注册会员
2023-02-26 19:28

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > no, because the PRINTF(15.68) of the output is a real value, is not an integer. In C, the %d formatter prints out integers and the %f formatter prints out real(floating-point) numbers, so if you want to print out the real number 15.68, you can use the following statement:

printf("%.2f", 15.68);


Where %.2f means that 2 decimal places are reserved to output real numbers. After executing this statement, the program will print 15.68. If you want to assign this real number to a variable a, you can use the following statement:

double a = 15.68;


In this case, the value of a is 15.68. If you want to print the value of a in a program, you can use the following statement:

printf("%.2f", a);


In this case, the program will print 15.68. Note that when printing real numbers, be sure to use the %f formatter and specify the number of decimal places you want to keep, otherwise the program will print real numbers in the default format, which may be incorrect.

About the Author

Question Info

Publish Time
2023-02-26 19:28
Update Time
2023-02-26 19:28