描述:
从输入任意个整型数,统计其中的负数个数并求所有非负数的平均值。
输入:
输入任意个整数
输出:
输出负数个数以及所有非负数的平均值
注意:
当输入的数字的个数未知时,ivec的用法,以\0结束输入
样例测试:
输入:
-13 -4 -7
输出:
3 0.0 |
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,pos=0,neg=0,sum=0;
while(cin>>n)
{
if(n>=0)
{
pos++;
sum+=n;
}
else
neg++;
}
cout<<neg<<endl;
if(pos!=0)
cout<<fixed<<showpoint<<setprecision(1)<<float(sum)/pos<<endl;
else
cout<<fixed<<showpoint<<setprecision(1)<<float(pos)<<endl;
//system("pause");
return 0;
}