实验十
来源:互联网 发布:泰拉瑞亚神器软件 编辑:程序博客网 时间:2024/05/01 08:21
LAP10
/*
输入一组非零整数(已输入0作为输入结束标志)到一维数组中,设计一个程序,
求出这一组数的平均值,并分别统计出这一组数中正数和负数的个数。
*/
#include<iostream>#include<conio.h>using namespace std;int main(){ int average = 0; int countsOfPos = 0; int countsOfNeg = 0; int sum = 0; int num = 0; do{ cout<<"Enter an integer(0 to exit):"<<endl; sum = sum + num; if(num > 0) countsOfPos++; else if(num < 0) countsOfNeg++; cin>>num; }while(num != 0); average = sum / (countsOfNeg + countsOfPos); cout<<"The average : "<<average<<endl <<"The number of positive numbers is :"<<countsOfPos<<endl <<"The number of negative numbers is :"<<countsOfNeg<<endl; _getch(); return 0;}