C Primer plus 第六版 第二章课后习题答案

C Primer plus 第六版 第二章课后习题答案

第一题
#include <iostream>
using std::cout;
using std::endl;
int main() {
	cout << "BeanGuohui" << endl;
	cout << "成都" << endl;
	getchar();
}
第二题
#include <iostream>
#include <Windows.h>
using std::cin;
using std::cout;
using std::endl;

int main() {
	cout << "请输入一个以long为单位的距离:";
	double distance;
	cin >> distance;
	cout << distance << " long = " << distance * 220 << " 码" << endl;
	system("pause");

}
第三题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

void FirstPrint(){
	cout << "Three blind mice" << endl;
}
void SecondPrint() {
	cout << "See how they run" << endl;
}

int main() {
	FirstPrint();
	FirstPrint();
	SecondPrint();
	SecondPrint();
	system("pause");
}

第四题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

int main() {
	cout << "Enter your age: ";
	int age = 0;
	cin >> age;
	cout << "该年龄包含" << age * 12 << "个月!" << endl;
	system("pause");

}
第五题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

double ChangeTemperature(double CentigradeTemperature) {
	return 1.8 * CentigradeTemperature + 32.0;

}

int main() {
	double CentigradeTemperature = 0;
	cout << "Please enter a Celsius value: ";
	cin >> CentigradeTemperature;

	cout << CentigradeTemperature << " degrees Celeius is " <<
		ChangeTemperature(CentigradeTemperature) << " degrees Fahrenheit." << endl;



	system("pause");

}
第六题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

double changeLightYear(double lightYear) {
	return 63240 * lightYear;
}

int main() {
	double lightYear = 0;
	cout << "Enter the number of light years: ";
	cin >> lightYear;

	cout << lightYear << " light year = " <<
		changeLightYear(lightYear) << " astronomical units." << endl;



	system("pause");

}
第七题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

void showData(int hour, int minute) {
	cout << "Time: " << hour << ":" << minute << endl;
}

int main() {
	int hour = 0, minute = 0;
	cout << "Enter the number of hours: ";
	cin >> hour;
	cout << "Enter the number of minutes: ";
	cin >> minute;
	showData(hour, minute);

	system("pause");

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值