orthog.cpp

来自「c++的数学物理方程数值算法源程序。这是"Numerical Methods f」· C++ 代码 · 共 35 行

CPP
35
字号
// orthog - Program to test if a pair of vectors // is orthogonal.  Assumes vectors are in 3D space#include <iostream.h>
void main() {  //* Initialize the vectors a and b  double a[3+1], b[3+1];
  cout << "Enter the first vector" << endl;  int i;
  for( i=1; i<=3; i++ ) {    cout << "  a[" << i << "] = ";    cin >> a[i];  }  cout << "Enter the second vector" << endl;  for( i=1; i<=3; i++ ) {    cout << "  b[" << i << "] = ";    cin >> b[i];  }  //* Evaluate the dot product as sum over products of elements  double a_dot_b = 0.0;  for( i=1; i<=3; i++ )    a_dot_b += a[i]*b[i];  //* Print dot product and state whether vectors are orthogonal  if( a_dot_b == 0.0 )    cout << "Vectors are orthogonal" << endl;  else {    cout << "Vectors are NOT orthogonal" << endl;    cout << "Dot product = " << a_dot_b << endl;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?