【C++ Primer Plus习题】7.7

问题:



解答:

cpp 复制代码
#include <iostream>
using namespace std;

#define SIZE 10

double* fill_array(double* begin, double* end)
{
	for (begin; begin < end; begin++)
	{
		cout << "请输入值:";
		cin >> *begin;
		if (cin.fail())
		{
			cout << "非法数字,结束输入!" << endl;
			break;
		}
	}
	return begin;
}

void show_array(double* arr, double* end)
{
	double* n = arr;
	cout << "数组信息为:";
	for (n; n < end; n++)
	{
		cout << *n << "  ";
	}
	cout << endl;
}

void revalue(double r, double* arr, double* end)
{
	double* n = arr;
	for (n; n < end; n++)
	{
		(*n) *= r;
	}
}

int main()
{
	double array[SIZE];
	double* begin = &array[0];
	double* end = &array[SIZE];

	double *index=fill_array(begin, end);
	show_array(array, index);
	revalue(2, array, index);
	show_array(array, index);

	return 0;
}

运行结果:

考查点:

  • 数组和指针

2024年8月30日21:16:55

相关推荐
小乖兽技术9 分钟前
在 .NET 8 开发的WinForms 程序中展示程序版本号的几种方式
开发语言·c#·.net
zyhomepage19 分钟前
科技的成就(六十八)
开发语言·人工智能·科技·算法·内容运营
slandarer20 分钟前
MATLAB | R2025a 更新了哪些有趣的东西?
开发语言·matlab
瑞雪兆丰年兮21 分钟前
数学实验(Matlab编程基础)
开发语言·算法·matlab·数学实验
✿ ༺ ོIT技术༻25 分钟前
笔试强训:Day5
c++·算法
oneDay++36 分钟前
# IntelliJ IDEA企业版集成AI插件「通义灵码」全流程详解:从安装到实战
java·经验分享·学习·intellij-idea·学习方法
代码小将36 分钟前
Leetcode76覆盖最小子串
笔记·学习·算法
努力的小帅40 分钟前
C++_STL_map与set
开发语言·数据结构·c++·学习·leetcode·刷题
yezipi耶不耶1 小时前
Rust入门之高级Trait
开发语言·后端·rust
邝邝邝邝丹1 小时前
React学习———React Router
前端·学习·react.js