Yjkaixuexi @ 2024-11-16 19:37:56
B2055 均值 为啥全错 大佬995 devc++没问题
#include<bits/stdc++.h>
using namespace std;
int main(){
float n,b=0;
int a[105];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
b=b+a[i];
}
float w=b/n;
cout<<b<<" "<<w;
}
by Yjkaixuexi @ 2024-11-16 19:44:07
回复即关注
by Z_HX_QAQ @ 2024-11-16 19:51:52
数组也要是浮点数
by Z_HX_QAQ @ 2024-11-16 19:52:26
还有输出有问题
by Yjkaixuexi @ 2024-11-16 20:00:27
一定要用printf吗
by Yjkaixuexi @ 2024-11-16 20:00:54
@Z_HX_QAQ
by Yjkaixuexi @ 2024-11-16 20:02:50
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a[105],x=0;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
if(a[i]>=x){
x=a[i];
}
}
cout<<x;
return 0;
}
这个也帮忙看一下
by TimADE @ 2024-11-16 20:08:21
@Yjkaixuexi 1
by Yjkaixuexi @ 2024-11-16 20:11:54
B2057 最高的分数 @TimADE
没过
by Z_HX_QAQ @ 2024-11-16 20:31:26
@Yjkaixuexi
吐槽一句:你没发现n没输入吗?
更优解:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x,maxn,i;
cin>>n>>x;
maxn=x;
for(i=2;i<=n;i++){
cin>>x;
if(maxn<x) maxn=x;
}
cout<<maxn;
return 0;
}
by Z_HX_QAQ @ 2024-11-16 20:32:13
@Yjkaixuexi 最好用printf,方便又正确