AcWing 716. 最大数和它的位置-语法题-C++
原题链接
中等
作者:
码
,
2020-05-23 17:38:28
,
所有人可见
,
阅读 1201
写法一:
#include<iostream>
using namespace std;
int main()
{
int maxn=0,max_index=0,x;
int n=1;
while(n<=100)
{
cin>>x;
if(x>maxn)
maxn=x,max_index=n;
n++;
}
cout<<maxn<<endl;
cout<<max_index;
return 0;
}
写法二:
#include<iostream>
using namespace std;
int number[101];
int main()
{
int max,t;
//先假设第一个数为最大的数
cin>>number[1];
max=1;
for(int i=2;i<=100;i++)//输入第2-100个数
{
cin>>number[i];
if(number[i]>number[max]) max=i;
}
cout<<number[max]<<endl<<max;
return 0;
}
```#include[HTML_REMOVED]
using namespace std;
int main()
{
int max=0;int a;
int b;//a代表输入的数,b代表位置
for(int i=1;i<=100;i++)
{
cin>>a;
if(a>max)
{ max=a;
b=i;
}
}
```
我的代码有什么问题吗?
为什么通不过呢