用printf函数输出
#include <stdio.h>
int main()
{
printf("Hello World!\n");
printf("Welcome\nto\nBeijing!\n");
return 0;
}
用于整型数据的输出格式控制
#include <stdio.h>
int main(){
printf("%d\n", 1234);
printf("%6d\n", 1234);
printf("%o\n", 1234);
printf("%x\n", 1234);
printf("%X\n", 1234);
printf("%u\n", -1234);
return 0;
}
用于浮点型数据的输出格式控制
#include <stdio.h>
int main(){
printf("%f\n", 1234.56);
printf("%10.3f\n", 1234.56);
printf("%e\n", 1234.56);
printf("%E\n", 1234.56);
printf("%g\n", 1234.567);
printf("%g\n", 1234567.89);
return 0;
}
避免参数和转换描述之间的类型的不匹配
#include <stdio.h>
int main()
{
int a, b, c;
scanf("%d %d", &a, &b);
c = a + b;
printf("%d + %d = %d\n", a, b, c);
printf("%f + %f = %f\n", a, b, c);
return 0;
}
避免参数和转换描述之间个数不匹配
#include <stdio.h>
int main()
{
int a, b, c;
scanf("%d %d", &a, &b);
c = a + b;
printf("%d + %d = %d\n", a, b);
printf("%d + %d = %d\n", a, b, c, a);
return 0;
}