题目描述
从键盘输入任意20个整型数,统计其中的负数个数并求所有正数的平均值。
保留两位小数
输入
输出
样例输入
1 2 3 4 5 6 7 8 9 10
-1 -2 -3 -4 -5 -6 -7 -8 -9 -10
样例输出
10
5.50
代码
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
float i=0,j,m=0,temp=0,n;
for (i=0;i<20;i++) {
cin>>j;
if(j<0) {
m=m+1;
}
if(j>0) {
temp=temp+j;
}
}
n=temp/(20-m);
cout<<m<<endl;
cout<<fixed<<setprecision(2)<<n<<endl;
return 0 ;
}
#include <iomanip>
using namespace std;
int main() {
float i=0,j,m=0,temp=0,n;
for (i=0;i<20;i++) {
cin>>j;
if(j<0) {
m=m+1;
}
if(j>0) {
temp=temp+j;
}
}
n=temp/(20-m);
cout<<m<<endl;
cout<<fixed<<setprecision(2)<<n<<endl;
return 0 ;
}