65,209
社区成员
发帖
与我相关
我的任务
分享
?怎么回事?
#include<iostream>
using namespace std;
#define N 10
int searchmax(int s[],int n,int &a)
{
a=1;
int max=s[0];
for(int i=1;i<n;i++)
{
if(s[i]>max)
{
max=s[i];
a=i+1;
}
}
return max;
}
int main()
{
int a[N],x,max;
cout<<"Input "<<N<<" numbers:"<<endl;
for(int i=0;i<N;i++)
{
cout<<"Input the "<<i+1<<" number:";
cin>>a[i];
}
cout<<endl;
max=searchmax(a,N,x);
cout<<"The max number is:"<<max<<endl;
cout<<"The position is:"<<x<<endl;
system("pause");
}
看看这个,试一下。[/quote]
嗯,谢了,我理解下代码
教科书般的越位
#include<iostream>
using namespace std;
#define N 10
int searchmax(int s[],int n,int &a)
{
a=1;
int max=s[0];
for(int i=1;i<n;i++)
{
if(s[i]>max)
{
max=s[i];
a=i+1;
}
}
return max;
}
int main()
{
int a[N],x,max;
cout<<"Input "<<N<<" numbers:"<<endl;
for(int i=0;i<N;i++)
{
cout<<"Input the "<<i+1<<" number:";
cin>>a[i];
}
cout<<endl;
max=searchmax(a,N,x);
cout<<"The max number is:"<<max<<endl;
cout<<"The position is:"<<x<<endl;
system("pause");
}
看看这个,试一下。
for(int i=0;i<10;i++)
{
cout<<a[i]<<endl;
}