输入scanf
//读取整数
scanf("%d", &a);
//读取浮点数, double类型必须要用%lf
scanf("%lf", &b);
//读取字符串(遇到空格停止)
scanf("%s", c); //不需要 &
输出printf
//输出整数
printf("%d\n", a);
//输出浮点数(默认是6位小数)
printf("%f\n", b);
//输出两位小数
printf("%.2f\\n", b);
特殊格式处理
控制输出宽度
int n = 123;
printf("%5d\n", n); //输出“ 123”(右对齐)
printf("%-5d\n", n); //输出“123 ”(左对齐)
读取一整行(包含空格)
char str[100];
scanf(" %[^\n]", str);

被折叠的 条评论
为什么被折叠?



