Instruction
1
Check out mathematical theory. The vector has two main parameters that characterize it: the length and direction. Ask both is possible by writing the vector as: a=xi+yj+zk, where i, j, k – unit vectors of the coordinate system, and x, y, z – coefficients. Thus the vector is specified as a number of individual segments. If the length does not matter, then carried out "normalization": the process in which the vector is reduced to a standard unit length, retaining only information about the direction. Mathematically, the operation is that each coordinate should be divided into the module of the vectorequal to (x^2+y^2+z^2)^1/2 (square root of sum of squares).
2
The algorithm implementation is the same for all programming languages, however, in order to avoid confusion, the code will be given only for language.
3
Display information about the request. This can be done with the command printf(“Enter the coefficients of i, j, k:”);. The user will need to enter three values separated by spaces. In the code they will be saved as x, y, z float (fractional).
4
Save user-entered data. Read more convenient to arrange with the command cin are in the iostream library.h. The line of code will look like the following: cin>>x>>y>>z;.
5
Calculate and save the value of the modulus of the vector. Connect the math library.h, create a variable M of type float, and enter a calculation formula: S=sqrt(x*x+y*y+z*z);. Use the "square" in this case is irrational.
6
Check whether the vector is zero. To do this, put the condition: if (S==0) printf(“Vector zero”), the next part of the program of record under the tab else { ... } where the ellipsis is the code below. So you implement a fork for the two cases.
7
The normalized values do not necessarily save, if you only display them on the screen. Calculation and output in this case can be combined in one action by writing a line of code: printf (“a(n)=%di+%dy+%dz”, x/s, y/s, z/s).
8
Put the command getch(); so the console was not closed after task execution.