4.8 编程练习(1-6)(C Primer Plus 第6版 中文版)

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;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值