例1: 输出int数据类型用“%d”
#include<stdio.h>
int main()
{
int a=5,b,c,d,e,f;
b=a+2;
c=b-a;
d=a*c;
e=a/d;
f=a%d;
printf("a=%d,b=%d,c=%d\n",a,b,c);
printf("e=%d,f=%d\n",e,f);
return 0;
}
输出结果
a=5,b=7,c=2
e=0,f=5
例2: 输出double数据类型用“%f”
#include<stdio.h>
int main()
{
double a,b,c,s;
a=3.67;
b=5.43;
c=6.21;
s=(a+b+c)/3;
printf("设定的a是%f,b是%f,c是%f\n",a,b,c);
printf("求得的s是%f\n",s);
return 0;
}
运行结果:
设定的a是3.670000,b是5.430000,c是6.210000
求得的s是5.103333
例3: 输出char数据类型用“%c”
#include<stdio.h>
int main()
{
char a='B',b='O',c='Y';
a=a+32;
b=b+32;
c=c+32;
printf("小写字母依次是%c%c%c",a,b,c);
return 0;
}
运行结果:
小写字母依次是boy