C语言printf();语句的作用

来源:百度知道 编辑:UC知道 时间:2024/05/16 14:50:59
#include "stdio.h"
#include "conio.h"
void main()
{ int a, b;
float d, e;
char c1, c2;
double f, g;
long m, n;
unsigned int p, q;
a=61; b=62;
c1='a'; c2='b';
d=5.67; e=-6.78;
f=1234.56789; g=0.123456789;
m=50000; n=-60000;
p=32768; q=40000;
printf("a=%d,b=%d\nc1=%c,c2=%c\n",a,b,c1,c2);
printf("d=%6.2f,e=%6.2f\n",d,e);
printf("f=%15.6f,g=%15.10f\n",f,g);
printf("m=%ld,n=%ld\np=%u,q=%u\n",m,n,p,q);
getch();
}
⑴ 运行所给出的源程序,对照结果分析各printf()语句的作用。

printf("a=%d,b=%d\nc1=%c,c2=%c\n",a,b,c1,c2);
a=61,b=62 整型
c1=a,c2=b 字符型

printf("d=%6.2f,e=%6.2f\n",d,e);
d=5.67,e=-6.78 浮点型, 2位小数,一共6位

printf("f=%15.6f,g=%15.10f\n",f,g);
f=1234.567890,g=0.1234567890;
f浮点型, 6位小数,一共15位
g浮点型, 10位小数,一共15位

printf("m=%ld,n=%ld\np=%u,q=%u\n",m,n,p,q);
m=50000,n=-60000 长整型
p=32768,q=40000 无符号整型

输出整型、字符型、共占6位小数点后保留2位的浮点型、共占15位小数点后保留6/10位的浮点型、长整型,最后%u没用过