C++程序设计教程 第3版——习题第六章

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

提示:这里可以添加本文要记录的大概内容:
有关第六章的习题解答


一、题目

请添加图片描述

二、代码解答

1-3

代码如下(示例):

1.#include<iostream>
#include"sx.h"
using namespace std;
int main()
{
	double a,b,c,m;
	cin>>a>>b>>c;
	m=max(a,b);
	m=max(m,c);
	cout<<m<<endl;
	return 0;
}
2.#include<iostream>
using namespace std;
#define CF(a,b) a*b
int main()
{
	int a,b,c;
	cin>>a>>b;
	c=CF(a,b);
	cout<<c<<endl;
	return 0;
}
3.#include<iostream>
using namespace std;
#define MAX(a,b) a<b?b:a;
int main()
{
	double a,b,c,m;
	cin>>a>>b>>c;
	m=MAX(a,b);
	m=MAX(m,c);
	cout<<m<<endl;
	return 0;
}

2.4和5

代码如下(示例):

4.#include<iostream>
using namespace std;
#define PI 3.1415926
#define S(r) PI*r*r
int main()
{
	double r,s;
	cin>>r;
	s=S(r);
	cout<<s<<endl;
	return 0;
}
5.#include<iostream>
using namespace std;
#define CHANCE 
int main()
{
	char ch;
	cin.get(ch);
	while(ch!='\n')
	{
     #if CHANCE 1
		if(ch<119&&ch>96) ch=ch+4;
		else switch(ch)
		{
			case 119:ch='a';break;
			case 120:ch='b';break;
			case 121:ch='c';break;
			case 122:ch='d';break;
		}
		cout<<ch;
     #else cout<<ch;
     #endif
		cin.get(ch);
	}
	cout<<endl;
	return 0;
}

---



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值