7.6
#include
using namespace std;
void Fill_array(double arr[],int arrSize) ;//因为是对数组进行操作,所以可以不用返回值;
void const Show_array(const double arr[],int arrSize);
void Reverse_array(double arr[],int arrSize);
void main76()
{
double arr[10];
Fill_array(arr,10);
Show_array(arr,10);
Reverse_array(arr,10);
system(“pause”);
}
void Fill_array(double arr[],int arrSize) //因为是对数组进行操作,所以可以不用返回值;
{
int i=0;//用于记录输入了多少个数字
for(i=0;i<arrSize;i++)
{
cout<<”\nPlease enter the “<<i+1<<” double values:”;
if(!(cin>>arr[i]))//如果输入非法值,跳出循环
break;
}
cout<<”\n you had input “<<i<<” values!”<<endl;
}
void const Show_array(const double arr[],int arrSize)
{
cout<<”the array is:”<<endl;
for(int i=0;i<arrSize&&arr[i]!=’\0’;i++)
cout<<arr[i]<<” “;
cout<<”\nshow end!”<<endl;
}
void Reverse_array(double arr[],int arrSize)
{
int temp;
cout<<”\nnow Reverse the array!”<<endl;
for(int i=1;i<arrSize/2;i++)
{
temp=arr[i];
arr[i]=arr[arrSize-1-i];
arr[arrSize-1-i]=temp;
}
cout<<”this is the new array:”<<endl;
Show_array(arr,arrSize);
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案76/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!