-------------------------------------------------------*/
#include <iostream>
using namespace std;
int main(){
cout<<"从键盘输入一组非0整数,以输入0标志结束:"<<endl;
/**********Program**********/
/********** End **********/
cout<<"平均值="<<average<<endl; //average代表平均值
cout<<"正数个数="<<pnum<<endl; //pnum代表正数个数
cout<<"负数个数="<<nnum<<endl; //nnum代表负数个数
return 0;
}
#include <iostream>
using namespace std;
int main(){
cout<<"从键盘输入一组非0整数,以输入0标志结束:"<<endl;
/**********Program**********/
int pnum=0,nnum=0,num,sum=0;
double average;
while(1)
{
cin>>num;
if(num>0)
pnum++;
else if(num<0)
nnum++;
else
break;
sum+=num;
}
average=sum*1.0/(pnum+nnum);
/********** End **********/
cout<<"平均值="<<average<<endl; //average代表平均值
cout<<"正数个数="<<pnum<<endl; //pnum代表正数个数
cout<<"负数个数="<<nnum<<endl; //nnum代表负数个数
return 0;
}
结果: