1.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
char name[40];
char surname[40];
printf("请输入您的名:\n");
scanf("%s", name);
printf("请输入您的姓:\n");
scanf("%s", surname);
printf("%s,%s", name, surname);
return 0;
}
2.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main(void)
{
char name[40];
printf("请输入您的姓名:\n");
scanf("%s", name);
printf("\"%s\"\n", name);
printf("\"%20s\"\n", name);
printf("\"%-20s\"\n", name);
printf("\"%*s\"\n", strlen(name)+3,name);
return 0;
}
3.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
float fraction;
printf("请输入一个小数:\n");
scanf("%f",&fraction);
printf("%f\n%2.1e\n", fraction,fraction);
return 0;
}
4.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
float feet;
char name[40];
printf("请输入身高:\n");
scanf("%f", &feet);
printf("请输入姓名:\n");
scanf("%s", name);
printf("%s,you are %2.1f feet tall\n", name, feet);
return 0;
}
5.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
float v,file,time;
printf("请输入下载速度(Mb/s):");
scanf("%f",&v);
printf("\n请输入文件大小(MB):");
scanf("%f", &file);
time = file*8 / v;
printf("\nAt %.2f megabits per second,a file of %.2f megabytes\ndownloads in %.2fseconds", v, file, time);
return 0;
}
6.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main(void)
{
char lastname[40];
char surname[40];
printf("请输入您的名:\n");
scanf("%s", lastname);
printf("请输入您的姓:\n");
scanf("%s", surname);
printf("%s %s\n", lastname, surname);
printf("%*d %*d\n", strlen(lastname), strlen(lastname), strlen(surname), strlen(surname));
printf("%s %s\n", lastname, surname);
printf("%-*d %-*d\n", strlen(lastname), strlen(lastname), strlen(surname), strlen(surname));
return 0;
}