4.2
输入名字,执行以下操作:
打印名字,包括双引号
在宽度为20的字段右端打印名字,包括双引号
在宽度为20的字段左端打印名字,包括双引号
在比姓名宽度宽3的字段中打印名字
#include <stdio.h>
#include <string.h>
int main(void)
{
char name[20];
printf("输入你的名字:>");
scanf_s("%s", name, 20);
printf("\"%s\"\n", name);
printf("\"%20s\"\n", name);
printf("\"%-20s\"\n", name);
printf("\"%*s\"\n", strlen(name) + 3, name);
return 0;
}
4.5
打印3个变量的值,显示为:
At 18.12 megabits per second, a file of of 2.20 megabytes
downloads in 0.97 second
#include <stdio.h>
int main(void)
{
float v = 18.12;
float file = 2.2;
float time = 0.97;
printf("At %.2f megabits per second, a file of of %.2f megabytes\ndownloads in %.2f second", v, file, time);
retu