user-0 提问: float型和double型的问题

回复:
user: user-0
content: 引用 13 楼 xiaohuh421 的回复:参数  有道词典结果 n. 论证；论据；争吵；内容提要 查看详细结果» 哦，是有啊，这微软真是的，好好说话不行吗，老用生僻字，头疼！

user: user-1
content: 参数  有道词典结果 n. 论证；论据；争吵；内容提要 查看详细结果»

user: user-0
content: 引用 2 楼 xiaohuh421 的回复:The type character is the only required format field; it appears after optional format fields.   The type character determines whether the associated argument is interpreted as a character, string, or number.   The types C and S, and the behavior of c and s with printf functions, are Microsoft extensions and are not ANSI-compatible.   printf Type Field Characters  Character Type Output Format  c int or wint_t When used with printf functions, specifies a single-byte character.  C int or wint_t When used with printf functions, specifies a wide character.  d int Signed decimal integer.  i int  Signed decimal integer.  o int  Unsigned octal integer.  u int  Unsigned decimal integer.  x int Unsigned hexadecimal integer, using "abcdef."  X int Unsigned hexadecimal integer, using "ABCDEF."  e  double Signed value having the form [ – ]d.dddd e [sign]ddd where d is a single decimal digit, dddd is one or more decimal digits, ddd is exactly three decimal digits, and sign is + or –.  E double Identical to the e format except that E rather than e introduces the exponent.  f double Signed value having the form [ – ]dddd.dddd, where dddd is one or more decimal digits.  The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.   g double Signed value printed in f or e format, whichever is more compact for the given value and precision.  The e format is used only when the exponent of the value is less than –4 or greater than or equal to the precision argument.   Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.   G double Identical to the g format, except that E, rather than e, introduces the exponent (where appropriate).  n  Pointer to integer  Number of characters successfully written so far to the stream or buffer; this value is stored in the integer whose address is given as the argument.  p Pointer to void Prints the address of the argument in hexadecimal digits.  s String  When used with printf functions, specifies a single-byte–character string.  Characters are printed up to the first null character or until the precision value is reached.   S String When used with printf functions, specifies a wide-character string.  Characters are printed up to the first null character or until the precision value is reached. “argument”在这里是如何翻译的，我查了下只有争论一类的意思呀？

user: user-2
content: printf("Sex=%c\nScore=%d\n\n", pstu->sex, pstu->score); 改成 printf("Sex=%c\nScore=%lf\n\n", pstu->sex, pstu->score);

user: user-0
content: 引用 7 楼 zhao4zhong1 的回复:printf里面的%和变量的一一对应关系 scanf里面的%和变量以及变量前加不加&的一一对应关系 是C代码中非常容易出错的地方，而且通常编译还不出错。 所以在编译源代码之前值得专门仔细检查一遍甚至多遍。 这个以后是得注意点，看来还是c++在输出上简单些，都不用这些格式控制符！

user: user-0
content: 引用 6 楼 starytx 的回复:格式化输出要和对应的数据类型匹配，整型用%d,浮点型用%f,double用%lf 谢谢，这才明白，看书马虎了

user: user-0
content: 引用 5 楼 mujiok2003 的回复:输出浮点数（double或float)，可以使用%f , %F, %e, %E, %g, %G ,%a , %A 输出长浮点数(long double),使用%Lf , %LF, %Le, %LE, %Lg, %LG ,%La , %LA  不要使用%d.谢谢，我查了下是有这么多的格式呀，我原来吧%d当作是输出双精度型了，马虎呀

user: user-3
content: printf里面的%和变量的一一对应关系 scanf里面的%和变量以及变量前加不加&的一一对应关系 是C代码中非常容易出错的地方，而且通常编译还不出错。 所以在编译源代码之前值得专门仔细检查一遍甚至多遍。

user: user-4
content: 格式化输出要和对应的数据类型匹配，整型用%d,浮点型用%f,double用%lf

user: user-5
content: 输出浮点数（double或float)，可以使用%f , %F, %e, %E, %g, %G ,%a , %A 输出长浮点数(long double),使用%Lf , %LF, %Le, %LE, %Lg, %LG ,%La , %LA  不要使用%d.

user: user-6
content: double是双精度浮点数，它的输出应该是%f或者%lf 而你的输出用的是%d，只能输出整数部分。  至于输出为0的话，则有可能是因为字节对齐的原因。 有可能双精度浮点数用8字节表示，%d取整数的时候取到了为0的高位。

user: user-7
content: Score在输入的时候应该用%lf

user: user-1
content: The type character is the only required format field; it appears after optional format fields.   The type character determines whether the associated argument is interpreted as a character, string, or number.   The types C and S, and the behavior of c and s with printf functions, are Microsoft extensions and are not ANSI-compatible.   printf Type Field Characters  Character Type Output Format  c int or wint_t When used with printf functions, specifies a single-byte character.  C int or wint_t When used with printf functions, specifies a wide character.  d int Signed decimal integer.  i int  Signed decimal integer.  o int  Unsigned octal integer.  u int  Unsigned decimal integer.  x int Unsigned hexadecimal integer, using "abcdef."  X int Unsigned hexadecimal integer, using "ABCDEF."  e  double Signed value having the form [ – ]d.dddd e [sign]ddd where d is a single decimal digit, dddd is one or more decimal digits, ddd is exactly three decimal digits, and sign is + or –.  E double Identical to the e format except that E rather than e introduces the exponent.  f double Signed value having the form [ – ]dddd.dddd, where dddd is one or more decimal digits.  The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.   g double Signed value printed in f or e format, whichever is more compact for the given value and precision.  The e format is used only when the exponent of the value is less than –4 or greater than or equal to the precision argument.   Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.   G double Identical to the g format, except that E, rather than e, introduces the exponent (where appropriate).  n  Pointer to integer  Number of characters successfully written so far to the stream or buffer; this value is stored in the integer whose address is given as the argument.  p Pointer to void Prints the address of the argument in hexadecimal digits.  s String  When used with printf functions, specifies a single-byte–character string.  Characters are printed up to the first null character or until the precision value is reached.   S String When used with printf functions, specifies a wide-character string.  Characters are printed up to the first null character or until the precision value is reached.

user: user-1
content: Score=%d   这里全部换成%f     %d是整数.

user: user-3
content: 引用 10 楼 u014496787 的回复:[quote=引用 7 楼 zhao4zhong1 的回复:] printf里面的%和变量的一一对应关系 scanf里面的%和变量以及变量前加不加&的一一对应关系 是C代码中非常容易出错的地方，而且通常编译还不出错。 所以在编译源代码之前值得专门仔细检查一遍甚至多遍。 这个以后是得注意点，看来还是c++在输出上简单些，都不用这些格式控制符！[/quote] 不用格式控制符,输出恰好是你期望的时候好说；等到输出不是你期望的时候，你会觉得还是用格式控制符更方便、更靠谱。  摒弃cin、cout 使用scanf,printf