运行结果:
Data in Array:
1 3 2 5 6 2 3 6 4 8
Max=8,Min=1,Average=4.00
代码:
#include
class Array
{
public:
Array(int a[10]);
void process();
void print();
private:
int data[10];
int max;
int min;
float average;
};
Array::Array(int a[10])
{
for (int i=0;i<10;i++)
data[i] = a[i];
}
void Array::process()
{
average = 0;
max = min = data[0];
for (int i=0;i<10;i++)
{
if (max < data[i])
max = data[i];
if (min > data[i])
min = data[i];
average+=data[i];
}
average/=10;
}
void Array::print()
{
printf("Data in Array:\n");
for (int i=0;i<10;i++)
printf("%d ",data[i]);
printf("\nMax=%d,Min=%d,Average=%.2f\n",max,min,average);
}
void main()
{
int a[10] = {1,3,2,5,6,2,3,6,4,8};
Array arr(a);
arr.process();
arr.print();
}
int[] data =data[10];
...//给里面放数字
int max =data[0];
int min =data[0];
float averge;
float sum=0;
for(int i=1;i
if(max max=data[i];
if(min>data[i])
min=data[i];
}
averge =sum/dat.length;