Here I wrote the program, but it seems that it does not calculate what is needed =) Task.

Write a program for calculating the phi angle between the vectors a=(a1,a2,a3) and b=(b1,b2,b3) . The components of the vectors are entered by the user. When calculating, use the relation a*b=|a|*|b|*cos(fi) .

 #include <iostream> #include <cmath> using namespace std; int main() { int i; double d; double a[3]; double b[3]; double res = 0; double f, h, alpha, y; cout << "a= "; for (i = 0; i < 3; i++) cin >> a[i]; cout << "b= "; for (i = 0; i < 3; i++) cin >> b[i]; for (i = 0; i < 3; i++) res += a[i] * b[i]; d = res; // Вот здесь чувствую у меня не правильно записано // (как это написать в цикле, чтобы в ручном режиме не писать) f = sqrt(a[1] * a[1] + a[2] * a[2] + a[3] * a[3]); h = sqrt(b[1] * b[1] + b[2] * b[2] + b[3] * b[3]); y = acos(d / (f * h)); cout << "alpha= " << y; system("PAUSE"); return 0; } 
  • one
    Mark out the code, no one will read this. Four spaces at the beginning, in the help written. Also use back quotes `. - Vladimir Gordeev

1 answer 1

Array indexes come from scratch. Those. true - f=sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);