登录站点

用户名

密码

用printf()函数输出整型、实型和字符型数据

已有 15 次阅读  2018-03-25 17:06
#include <stdio.h>
#include <string.h>
int main()
{
char c, s[20];
int a=1234;
float f=3.141592653589;
double x=0.12345678912345678;
strcpy(s,"Hello World");
c='\x41';

printf("a=%d\n",a);
printf("a=%d%%\n",a);
printf("a=%6d\n",a);
printf("a=%06d\n",a);
printf("a=%26d\n",a);
printf("a=%-6d\n",a);
printf("f=%f\n",f);
printf("f=%6.4f\n",f);
printf("x=%1f\n",x);
printf("x=%18.16lf\n",x);
printf("c=%c\n",c);
printf("c=%x\n",c);
printf("s[]=%s\n",s);
printf("s[]=%6.9s\n",s);
return 0;
}

得出结果

分享 举报