一、前言
我们学习程序开发的第一个编程基本就是输出。下面我们学习一下的输出函数printf并学习。
二、项目实践
1.引入库文件
#include <stdio.h>2.标准输出
标准格式:printf(格式控制字符串,输出列表);
#include <stdio.h>
int main()
{
	printf("helloworld\n");
	return 0;
}执行程序:

输出列表情况:
#include <stdio.h>
int main()
{
	printf("helloworld\n");
	printf("num is %d\n",8);
	return 0;
}执行程序:

多个占位符参数情况:
#include <stdio.h>
int main()
{
	printf("helloworld\n");
	int id = 10;
	printf("num is %d\n",id);
	printf("Tom's score=%d,level=%c\n", 90, 'A');
	return 0;
}执行程序:

格式控制字符串中占位符的个数要与输出列表中变量或常量的个数相同,而且要一一对应。
3.常见的占位符
| 占位符 | 含义 | 
| %c | char类型数据 | 
| %d | 十进制整数(int) | 
| %f | 浮点数 | 
| %ld | 十进制整数(long) | 
| %lf | 十进制浮点数(double) | 
| %p | 指针 | 
| %s | 字符串 | 
| %u | 十进制无符号整数(unsigned int) | 
#include <stdio.h>
int main()
{
	printf("num is %d\n", 5);
	printf("level is %c\n", 'B');
	printf("score is %f\n", 30.2);
	printf("score is %lf\n", 22233.30);
	printf("money is %ld\n", 888888);
	printf("name is %s\n", "aaa");
	printf("age is %u\n", 20);
	return 0;
}执行程序:

4.输出格式说明
4.1 限定宽度
#include <stdio.h>
int main()
{
	printf("num is %5d\n", 123);
	return 0;
}执行程序:

4.2 修改左对齐
#include <stdio.h>
int main()
{
	printf("num is %-5d\n", 123);
	return 0;
}执行程序:

4.3 显示正负号
#include <stdio.h>
int main()
{
	//+d
	printf("num is %+d\n", 5);
	printf("num is %d\n", -5);
	return 0;
}执行程序:

4.4限定小数位数
#include <stdio.h>
int main()
{
	//默认是6位小数
	printf("float is %f\n", 10.3);
	return 0;
}执行程序:

#include <stdio.h>
int main()
{
	//默认是5位小数 
	//设置2位小数
	printf("float is %.2f\n", 10.335);
	return 0;
}执行程序:











