#include <iostream>
#include <valarray>
#include <cmath>
using namespace std;
int main()
{
valarray<int> v(10);
int i;
for(i=0; i<10; i++) v[i] = i;
cout << "Original contents: ";
for(i=0; i<10; i++)
cout << v[i] << " ";
cout << endl;
valarray<double> fv(5);
for(i=0; i<5; i++) fv[i] = (double) i;
cout << "Original contents: ";
for(i=0; i<5; i++)
cout << fv[i] << " ";
cout << endl;
fv = sqrt(fv);
cout << "Square roots: ";
for(i=0; i<5; i++)
cout << fv[i] << " ";
cout << endl;
fv = fv + fv;
cout << "Double the square roots: ";
for(i=0; i<5; i++)
cout << fv[i] << " ";
cout << endl;
return 0;
}
|