Need a program that reads the parameters of the vectors (coordinates) and then calculates their scalar product

Closed due to the fact that off-topic participants fori1ton , PashaPash , null , user31688, Shilgen 5 May '15 at 16:45 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Questionnaires are forbidden on Stack Overflow in Russian . To get an answer, rephrase your question so that it can be given an unambiguously correct answer." - null, Shilgen
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 6
    @a_kliimov, This is a question for the FreeLancer forum. - ReinRaus
  • 2
    @ReinRaus here what template comment we lack is :) - VioLet
  • four
    Well, with multiplication you can help: double vecprod (int dim, double * vect1, double * vect2) {double s = 0; for (; dim--> 0; s + = * vect1 ++ * * * vect2 ++); return s; } dim is the dimension of the vectors. (sorry, forgotten the first increment) - alexlz
  • 3
    @alexlz, do not feed ... - ReinRaus
  • 6
    This is the limit of impudence. Do something yourself. - skegg

1 answer 1

One way:

#include <iostream> using namespace std; struct Vector{ double X, Y; Vector():X(0), Y(0) {} Vector(double x, double y):X(x), Y(y) {} Vector(int x, int y):X(static_cast<double> (x)), Y(static_cast<double> (y)) {} }; double Multiplication(const Vector &vec1, const Vector &vec2){ Vector temp; temp.X = vec1.X * vec2.X; temp.Y = vec1.Y * vec2.Y; return temp.X + temp.Y; } void main() { Vector vec1(1, 3); Vector vec2(1, 1); double result = Multiplication(vec1, vec2); cout << result; } 

And read here Linear algebra for game developers . Well written enough.