|
对六楼的稍微修改了一下:
#include<iostream>
using namespace std;
const int MAXSIZE = 100;
void read(int[],int&);
void summ(int& i,int& j,float& sum,int a[],int size);
int main()
{
int a[MAXSIZE] = {0},size,i,j;
float sum,avg;
read(a,size);
summ(i,j,sum,a,size);
avg=sum/(size-2);
cout<<i<<" "<<j<<" "<<sum<<" "<<avg<<endl;
return 0;
}
void read(int a[],int& n)
{
cout<<"Enter integers. Terminate with 0:\n";
n=0;
do
{
cout<<"a["<<n<<"]:";
cin>>a[n];
}while(a[n++]!=0 && n<MAXSIZE);
}
void summ(int& i,int& j,float& sum,int a[],int size)
{
sum = 0.0;
i = 0;
j = 0;
for(int k=0;k<=size;k++)
{
sum+=a[k];
if(a[k]>0)
i++;
if(a[k]<0)
j++;
}
} |
|