題目描述:
從鍵盤輸入任意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 <stdio.h>
using namespace std;
int main()
{
int b=0,c=0,a[20];
double d,sum;
for(int i=0;i<20;i++)
{
cin>>a[i];
}
sum=0;
for(int j=0;j<20;j++)
{
int temp;
temp=a[j];
if(temp>0)
{
b++;
sum+=a[j];
}
else if(temp<0)
c++;
}
d=sum/b;
cout<<c<<endl;
printf("%.2f\n",d);
return 0;
}