问题:
解答:
#include <iostream>
using namespace std;
#define SIZE 20
int Fill_array(double* arr, int len)
{
int i = 0;
for (i = 0; i < len; i++)
{
cout << "请输入值:";
cin >> arr[i];
if (cin.fail())
{
cout << "输入非法数字,结束输入!" << endl;
break;
}
}
return i;
}
void Show_array(double* arr, int len)
{
cout << "数组元素为:" << endl;
for (int i = 0; i < len; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}
void Reverse_array(double* arr, int len)
{
int j = len - 1;
for (int i = 0; i < j; i++, j--)
{
double temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int main()
{
double array[SIZE];
int size=0;
size=Fill_array(array, SIZE);
Show_array(array, size);
Reverse_array(array, size);
Show_array(array, size);
Reverse_array(&array[1], size-2);
Show_array(array, size);
return 0;
}
运行结果:
考查点:
- 数组逆转
2024年8月30日20:46:04
标签:arr,cout,int,len,7.6,习题,Primer,array,size From: https://blog.csdn.net/qq_74047911/article/details/141726957