Facebook
From Sole Mockingjay, 7 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 305
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.         double **A = new double *[3];
  8.  
  9.  
  10.         double x = 0;
  11.         double y = 0;
  12.         double z = 0;
  13.        
  14.         float tmp_x, tmp_y, tmp_z;
  15.  
  16.         for(int i = 0; i < 3; i++){
  17.                 A[i] = new double [3];
  18.         }
  19.                 A[0][0] = 5;
  20.                 A[0][1] = -2;
  21.                 A[0][2] = 3;
  22.                 A[1][0] = 2;
  23.                 A[1][1] = 4;
  24.                 A[1][2] = 2;
  25.                 A[2][0] = 2;
  26.                 A[2][1] = -1;
  27.                 A[2][2] = -4;
  28.  
  29.                 double *B = new double[3];
  30.                 B[0] = 10;
  31.                 B[1] = 0;
  32.                 B[2] = 0;
  33.        
  34.  
  35.         for(int j = 0; j < 10; j++){
  36.                 tmp_x = (B[0] - A[0][1] * y - A[0][2] * z)/A[0][0];
  37.                 tmp_y = (B[1] - A[1][0] * x - A[1][2] * z)/A[1][1];
  38.                 tmp_z = (B[2] - A[2][0] * x - A[2][1] * y)/A[2][2];
  39.  
  40.                 x = tmp_x;
  41.                 y = tmp_y;
  42.                 z = tmp_z;
  43.  
  44.                 cout << "X = " << x << " Y = " << y << " Z: " << z << endl;
  45.         }
  46.  
  47.  
  48.  
  49.         cout << A[0][0] * x + A[0][1] * y + A[0][2] * z << endl;
  50.         cout << A[1][0] * x + A[1][1] * y + A[1][2] * z << endl;
  51.         cout << A[2][0] * x + A[2][1] * y + A[2][2] * z << endl;
  52.  
  53.         system("PAUSE");
  54. }