【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

相关推荐
xlq223225 小时前
22.多态(上)
开发语言·c++·算法
666HZ6665 小时前
C语言——高精度加法
c语言·开发语言·算法
星释5 小时前
Rust 练习册 100:音乐音阶生成器
开发语言·后端·rust
c***21295 小时前
Springboot3学习(5、Druid使用及配置)
android·学习
D_evil__6 小时前
[C++高频精进] 并发编程:线程基础
c++
风生u6 小时前
go进阶语法
开发语言·后端·golang
666HZ6666 小时前
C语言——黑店
c语言·开发语言
Gomiko6 小时前
JavaScript基础(八):函数
开发语言·javascript·ecmascript
〝七夜5696 小时前
JVM内存结构
java·开发语言·jvm
GISer_Jing6 小时前
jx前端架构学习
前端·学习·架构