我试图以较小的方案为例,说明为什么会出现更大的问题。 这一较小的方案并不奏效,因此我相信,这是我对缺陷的职能的理解。
As far as I (had) believed, the following program should initialise a string with up to 30 characters, then take the number 5 to nine significant figures, and turn it into that string. The program should then print the value 5.00000000 . However, the program prints the value 7.96788(...). Why is this?
#include <stdio.h>
int main()
{
char word[30];
sprintf(word, "%.9g", 5);
printf(word);
return 0;
}