#include <iostream>
#include <valarray>
using namespace std;
int main(void)
{
valarray<double> v1(10),v2(10);
for(int i = 0; i < 10; ++i)
{
v1[i] = static_cast<double>(i);
v2[i] = i * 40.5;
}
v1 *= 1.1;
for(size_t i = 0; i < v1.size(); ++i)
cout << v1[i] << "\t";
cout << endl;
cout << v1.max() << "\t" << v1.min() << endl;
cout << v1.sum() << endl;
for(size_t i = 0; i < v1.size(); ++i)
cout << v2[i] << "\t";
cout << endl;
cout << v2.max() << "\t" << v2.min() << endl;
cout << v2.sum() << endl;
v1 += v2;
for(size_t i = 0; i < v1.size(); ++i)
cout << v1[i] << "\t";
cout << endl;
cout << v1.max() << "\t" << v1.min() << endl;
cout << v1.sum() << endl;
return 0;
}
本文地址:http://com.8s8s.com/it/it24969.htm