valarray

#include<iostream>
#include<valarray>
using namespace std;

int main()
{
    srand(time(0));
    int a[10];
    for(int i=0;i<10;i++)
        a[i]=rand()%10;
    valarray<int> v(a,sizeof(a)/sizeof(*a));
    for(int i=0;i<10;i++)
        cout << a[i] << " ";
    cout << endl;
    int sum = v.sum();
    int min = v.min();
    int max = v.max();
    int avg = sum/v.size();
    int mid = v[v.size()/2];
    cout << "sum:" << sum << "min:" << min << "max:" << max << "avg:" << avg << "mid:" << mid << endl;
}

你可能感兴趣的:(C++,c,C#)