C Primer Plus第四章

第四章复习题

#include <stdio.h>
#include <limits.h>
#include <Windows.h>
int main(void){
	//任务:跳过输入中的两个整数
	int n;
	scanf("%*d %*d %d",&n);
	printf("%d\n",n);
	
	//getchar();
	system("pause");
	return 0;
}

#include <stdio.h>
#include <limits.h>
#include <Windows.h>
#define BOOK "war and peace"

int main(void){
	//任务:构造一个使用BOOK、cost和percent的输出语句
	float cost = 1.23;
	float percent = 80.0;

	printf("The book named \"%s\",it costs $%.2f\n",BOOK,cost);
	printf("it's percent is %.2f%%\n",percent);
	
	//getchar();
	system("pause");
	return 0;
}

#include <stdio.h>
#include <limits.h>
#include <Windows.h>

int main(void)
{
	//提示用户输入身高和姓名
    float feet;
	char name[30];
	float cm;

	printf("请输入身高和姓名:\n");
	scanf("%f %s",&feet,&name);

	printf("%s,you are %.3f feet tall!\n",name,feet);
	cm = feet * 6.208;
	printf("%s,you are %.3f cm tall!\n",name,cm);

	system("pause");
    return;
}

#include <stdio.h>
#include <limits.h>
#include <Windows.h>

int main(void)
{
	//提示用户输入以Mb/s为单位的下载速度和以Mb为单位的文件大小
	//程序中应计算文件的下载时间
    float MB,Mbs,time;
	scanf("%f %f %f",&MB,&Mbs,&time);
	printf("At %.2f mbs,a file of %.2f mb\n",Mbs,MB);
	printf("downloads in %.2f seconds",time);

	system("pause");
    return;
}

#include <stdio.h>
#include <string.h> //提供strlen函数的原型
#include <limits.h>
#include <Windows.h>

int main(void)
{
	//用户输入名字和姓,然后输出名和姓的字母数
	//程序中应计算文件的下载时间
    char name[30];
	char xing[30];
	
	printf("请输入名和姓:\n");
	scanf("%s %s",&name,&xing);
	printf("%s %s\n",name,xing);
	//	printf("%zd %zd\n",strlen(name),strlen(xing));	编译器不识别%zd,换成%u或者%lu
	printf("%-3u %-3u\n",strlen(name),strlen(xing));

	system("pause");
    return;
}

#include <stdio.h>
#include <limits.h>
#include <Windows.h>
#include <float.h>

int main(void)
{
	//	double的1/3 和 float的1/3相比
    double a;
	float b;
	a = 1.0/3.0;
	b = 1.0/3.0;
	printf("%.6lf\n",a);
	printf("%.12lf\n",a);
	printf("%.16lf\n",a);

	printf("%.6f\n",b);
	printf("%.12f\n",b);
	printf("%.16f\n",b);

	system("pause");
    return;
}

#include <stdio.h>
#include <limits.h>
#include <Windows.h>

#define KM_PER_MILE (1.609)
#define PINT_PER_GALLON (3.785)
int main(void)
{
	//提示用户输入旅行的历程和消耗的汽油量
    float driven_distance = 0.0;
    float gas_consumption = 0.0;
    float pint_per_hundred_km = 0.0;
    float mile_per_gallon = 0.0;
    printf("How much distance have you traveled in kilometer:");
    scanf_s("%f", &driven_distance);
    getchar();
 
    printf("How much gas have you used in pint:");
    scanf_s("%f", &gas_consumption);
    getchar();
 
    pint_per_hundred_km = gas_consumption / driven_distance * 100;
    mile_per_gallon = (driven_distance / KM_PER_MILE) / (gas_consumption / PINT_PER_GALLON);
 
    printf("Fuel consumptions:%f pint/100km or %f mile/gallon\n", pint_per_hundred_km, mile_per_gallon);
}


书上的一些复习题,不会的可以去其他博主那找,因为个人能力有限,想探讨,也可以在我评论区评论,或者私信我,暑假有很多时间,可以回复

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

0泡果奶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值