正文

printf输出函数中%*c,%*d的用法小解2006-02-03 20:57:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/aaawn/9958.html

分享到:

可以用printf中的%*c、%*d,来输出前导空格:运行以下几个小程序即可发现其中奥妙:(%*c,%*d在printf()函数中的 妙用) 明白后可以运行最后的程序:字母金字塔;以体会如何运用。 main(){ char a='A';int d=40; while(d>0) printf("%*c,%c\n",d--,a);} ////////main(){ char a='A';int d=40; while(d>0)  printf("%*d,\n",d--,a);} /////////main(){ char a='A';int d=40; while(d>0)  printf("%*c,\n",d--,a);} /////////main(){ char a='A';int d=40; while(d>0)  printf("%*c\n",d--,a);} 字母金字塔程序代码: #include<stdio.h>#include<ctype.h>void main(void){ char c,c1,c2,top; printf("Input a character:\n"); top=isupper(c=getchar())?'A':(islower(c)?'a':'\0'); if(top) {  for(c1=top;c1<=c;++c1)  {   printf("%*c",40-(c1-top<<1));    for(c2=top;c2<=c1;++c2)     printf("%2c",c2);    for(c2=c1-1;c2>=top;--c2)     printf("%2c",c2);    printf("\n");  } }} ////////main(){ char a='A';int d=40; while(d>0)  printf("%*c,\n",d--);}

阅读(3870) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册