1、编写一个程序,提示用户输入名和姓, 然后以“名,姓”的格式打印出来。
#include <stdio.h> int main(void) { char name[128]; char surname[128]; printf("please input your name: "); scanf("%s", name); printf("please input your surname: "); scanf("%s", surname); printf("your whole name: %s,%s.\n", name, surname); return 0; }
2、编写一个程序,提示用户输入名字,并执行以下操作:
a、打印名字,包括双引号
#include <stdio.h> int main(void) { char name[128]; printf("please input your name: "); scanf("%s", name); printf("your name: \"%s\"\n", name); return 0; }
b、在宽度为20的字段右端打印名字,包括双引号:
#include <stdio.h> int main(void) { char name[128]; printf("please input your name: "); scanf("%s", name); printf("your name: \"%20s\"\n", name); return 0; }
c、在宽度为20的字段右端打印名字,包括双引号:
#include <stdio.h> int main(void) { char name[128]; printf("please input your name: "); scanf("%s", name); printf("your name: \"%20s\"\n", name); return 0; }
d、在比姓名宽度宽3的字段中打印名字
#include <stdio.h> #include <string.h> int main(void) { char name[128]; int namelen; printf("please input your name: "); scanf("%s", name); namelen = strlen(name) + 3; printf("your name: \"%*s\"\n", namelen, name); return 0; }
3、编写程序,读取一个浮点数,首先以小数点计数法打印,然后以指数计数法打印。 用下面的格式进行输出(系统不同,指数计数法显示的位数可能不同):
a. input is 21.3 or 2.1e+001.
#include <stdio.h> int main(void) { float num; printf("please input an float: "); scanf("%f", &num); printf("The input is %.1f or %.1e.\n", num, num); return 0; }
b. The input is +21.290 or 2.129E+001.
#include <stdio.h> int main(void) { float num; printf("please input an float: "); scanf("%f", &num); printf("The input is %+.3f or %.3E.\n", num, num); return 0; }
4、编写一个程序,提示用户输入身高(单位:英寸)和姓名,然后以下面的格式显示用户当输入的信息:
Dabey,you are 6.208feet tall。
#include <stdio.h> int main(void) { float height; printf("please input your height in inch:"); scanf("%f", &height); printf("Dabney, you are %.3f feet tall.\n", height / 12); return 0; }
5、……
#include <stdio.h> int main(void) { float netspeed, filesize, time; printf("please input the netspeed: "); scanf("%f", &netspeed); printf("please input the filesize: "); scanf("%f", &filesize); time = filesize * 8 / netspeed; printf("download im %.2f second.\n", time); return 0; }
6、