vector multiplication

Hello,


I have a vector that is filled with N values, now I need to multiply this vector with itself. Can anyone help?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 #include <iostream>
#include <vector>
using namespace std;

int main ()
{
	const int N = 16 * 2;
	double eta = 0.25;
  vector<double> myvector;
  const double MAX_ELEMS = N * eta;

  for (double i = 0.0; myvector.size() < MAX_ELEMS; i += eta) 
  {
		  myvector.push_back(i);
  }
  
  cout << "myvector contains:";

  for (unsigned i = 0; i < myvector.size(); i++)
    cout << ' ' << myvector.at(i);
  cout << '\n';

  return 0;
}
This would do...
1
2
3
4
for(std::size_t i=0;i<myvector.size();i++)
{
       myvector[i]*=myvector[i];
}
Topic archived. No new replies allowed.