想知道:Intmainscanf(&amp quot什么意思;%d&amp quot什么意思;,

unsigned int a = -1;printf(&%d&,a);输出为什么是_Java123社区微信号:java123msg |||[][]当前位置: &
& unsigned int a = -1;printf(&%d&,a);输出为什么是如题, #includestdio.h #includestdlib.h intmain(){ unsignedinta=-1; printf( %d\n ,a); return0; } 输出是-1;很疑惑,求解。 因为你的printf中用的是一般整数的输出。 无符号输出请用%u printf( %ud\n ,a) 作为一个如题,
#include&stdio.h&
#include&stdlib.h&
int&main(){
&&&&unsigned&int&a&=&-1;
&&&&printf("%d\n",a);
&&&&return&0;
输出是-1;很疑惑,求解。
因为你的printf中用的是一般整数的输出。
无符号输出请用%u
printf("%ud\n",a)
作为一个C程序员,对
&scanf,sscanf,fscanf
&printf,sprintf,fprintf
这类函数的用法,还是要做到“拳不离手,曲不离口”的。
%ud的效果是输出一个无符号整数&然后紧接着输出一个'd'
printf&Type&Field&Characters
The&type&character&is&the&only&required&format&field&;&it&appears&after&any&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.&
Table&R.3&&&printf&Type&Field&Characters
Character&Type&Output&Format&
c&int&or&wint_t&When&used&with&printf&functions,&specifies&a&single-byte&&when&used&with&wprintf&functions,&specifies&a&wide&character.&
C&int&or&wint_t&When&used&with&printf&functions,&specifies&a&wide&&when&used&with&wprintf&functions,&specifies&a&single-byte&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&&this&value&is&stored&in&the&integer&whose&address&is&given&as&the&argument.&
p&Pointer&to&void&Prints&the&address&pointed&to&by&the&argument&in&the&form&xxxx:yyyy&where&xxxx&is&the&segment&and&yyyy&is&the&offset,&and&the&digits&x&and&y&are&uppercase&hexadecimal&digits.&共2页顶一下(0)0%踩一下(0)0%------分隔线------上一篇: 下一篇: 栏目列表推荐内容#includeiostream int main() { bool flag= int a[50][50]...
下面有两段代码,只有红色标记部分的构造函数是不相同的。第...
将一个类的成员放在一个头文件中,函数的定义放在一个CPP实现...C语言例题_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
C​语​言​例​题
阅读已结束,如果下载本文需要使用
想免费下载本文?
你可能喜欢while((scanf(&%d&, &n))!=EOF)解决超时问题 - laznrbfe的博客 - 编程中国
while((scanf(&%d&, &n))!=EOF)解决超时问题
时间限制: ms | 内存限制:65535 KB
我们知道,如果一个数是水仙花数,当且仅当它的各位数字的三次方的和与这个数相等。如153 = 1 ^ 3 + 5 ^ 3 + 3 ^ 3则153是水仙花数
输入数据有若干组,每组一个三位数N(100&=N&=999)
每组测试数据一行,如果这个数是水仙花数,则输出“Yes”,否则输出“No”.
#include&stdio.h&#include&math.h&int main(){&&&&int n=<SPAN style="COLOR: #,a=<SPAN style="COLOR: #,b=<SPAN style="COLOR: #;&&&&while(scanf("%d",&a)&&&&{&&&&&&&&n=a;&&&&&&&&b=<SPAN style="COLOR: #;&&&&&&&&do&&&&&&&&{&&&&&&&&&&&&b=b+pow(a%<SPAN style="COLOR: #,<SPAN style="COLOR: #);&&&&&&&&&&&&a=a/<SPAN style="COLOR: #;&&&&&&&&}while(a);&&&&&&&&if(n==b)&&&&&&&&{&&&&&&&&&&&&printf("Yes\n");&&&&&&&&}&&&&&&&&else&&&&&&&&{&&&&&&&&&&&&printf("No\n");&&&&&&&&}&&&&}&&&&return <SPAN style="COLOR: #;}运行超时。1002ms。
改了while里面的循环判断语句
#include&stdio.h&#include&math.h&int main(){&&&&int n=<SPAN style="COLOR: #,a=<SPAN style="COLOR: #,b=<SPAN style="COLOR: #;&&&&while(scanf("%d",&a)!=EOF)/////////////&&&&{&&&&&&&&n=a;&&&&&&&&b=<SPAN style="COLOR: #;&&&&&&&&do&&&&&&&&{&&&&&&&&&&&&b=b+pow(a%<SPAN style="COLOR: #,<SPAN style="COLOR: #);&&&&&&&&&&&&a=a/<SPAN style="COLOR: #;&&&&&&&&}while(a);&&&&&&&&if(n==b)&&&&&&&&{&&&&&&&&&&&&printf("Yes\n");&&&&&&&&}&&&&&&&&else&&&&&&&&{&&&&&&&&&&&&printf("No\n");&&&&&&&&}&&&&}&&&&return <SPAN style="COLOR: #;}运行时间3ms!
浏览17956次
(5070)(4135)(677)(676)(616)(608)(561)(501)(467)(452)您还未登陆,请登录后操作!
scanf和printf()问题
int main()
{
scanf(&%d %d %5[a-z] %*s %f&,&i,&j,s,s);
printf(&%d %d %s\n&,i,j,s);
return 0;
}
输入 10 0x1b aaaaaaaa bbbbbbbb
结果 10 27 aaaaa
这是为什么,那位大侠解释一下!
还有如果在scanf里面%5[a-z]改成%s ,而且后面的%*s去掉,最后的输出应该是什么呀?为什么了?
一点愚见。。。
首先你一定没自己运行或者是打错了,没定义s的变量类型这样是编译不过去的。。。然后百度了一下有个类似的例子,没有char ch的定义而是定义了一个char s[5]的字符串(我觉得这个比较靠谱)
第二这个程序只是改完按你的输入输出也不是那个而是10 0 x
至于为什么。。。第二个读入是%d是不能读16进制数的,所以0和1中间的x被赋给了s
char s[5];
scanf(&#034;%d %x %5[a-z] %*s %f&#034;,&i,&j,s,s);
printf(&#034;%d %d %s\n&#034;,i,j,s);
可以得到你所说的第一个结果%x是读入16进制
即,10赋给i
x01b(十进制是27)赋给j aaaaaaaa中五位赋给s
而%f是不能赋给s的编译的时候会有warnings,说类型不匹配,所以最后的bbbbbbbb是无效的
一点愚见。。。
首先你一定没自己运行或者是打错了,没定义s的变量类型这样是编译不过去的。。。然后百度了一下有个类似的例子,没有char ch的定义而是定义了一个char s[5]的字符串(我觉得这个比较靠谱)
第二这个程序只是改完按你的输入输出也不是那个而是10 0 x
至于为什么。。。第二个读入是%d是不能读16进制数的,所以0和1中间的x被赋给了s
char s[5];
scanf(&#034;%d %x %5[a-z] %*s %f&#034;,&i,&j,s,s);
printf(&#034;%d %d %s\n&#034;,i,j,s);
可以得到你所说的第一个结果%x是读入16进制
即,10赋给i
x01b(十进制是27)赋给j aaaaaaaa中五位赋给s
而%f是不能赋给s的编译的时候会有warnings,说类型不匹配,所以最后的bbbbbbbb是无效的
可以单独试一下把aaaaaaaa用%f赋给s,结果是没有输出的
所以改后输出是
aaaaa(a的个数跟数组大小有关)
应该是错的 你只定义了i j 。s呢
您的举报已经提交成功,我们将尽快处理,谢谢!
大家还关注通信题目_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
文档贡献者
评价文档:
通&#8203;信&#8203;题&#8203;目
大小:824.00B
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢}

我要回帖

更多关于 yes.i.do什么意思 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信