代码如下:
#include
using namespace std;
int main()
{
int n = 0, sum = 0, cnt1 = 0, cnt2 = 0;
cout << "请输入一组整数,以0结束:";
cin >> n;
while (n != 0) {
sum += n;
if (n > 0)
cnt1++;
else
cnt2++;
cin >> n;
}
cout << "平均值:" << sum / (cnt1 + cnt2) << endl
<< "正数个数:" << cnt1 << endl
<< "负数个数:" << cnt2 << endl;
system("pause");
return 0;
}
运行结果: