【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

相关推荐
哥不想学算法4 小时前
【C++】字符串字面量拼接
开发语言·c++
AI云海5 小时前
利用好手机这个工具-碎片化学习
学习
gugucoding6 小时前
21. 【C语言】打包不同类型:结构体
c语言·开发语言
Brookty6 小时前
【JavaEE】线程安全(一).4:写块串行保安全、CAS
java·开发语言·java-ee·多线程·线程安全
F20226974867 小时前
西门子 PLC 与 C# 通信
开发语言·c#
gugucoding7 小时前
31. 【C语言】堆栈与队列的实现
c语言·开发语言·数据结构·链表
β添砖java7 小时前
2025最新快速构建企业级虚拟专用网络环境学习笔记
笔记·学习
万联WANFLOW8 小时前
多分支企业组网,IP 网段到底该怎么规划
开发语言·php
阿里嘎多学长8 小时前
2026-07-07 GitHub 热点项目精选
开发语言·程序员·github·代码托管