Tarango

Three Equations Solve

Oct 20th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define eps 0.000000001
  3. using namespace std;
  4.  
  5. int main() {
  6.     double a[10], b[10], c[10], d[10], x[10], y[10], z[10];
  7.     cout << "Enter coefficients of 3 variable equation\n";
  8.     for (int i = 0; i < 3; i++) {
  9.         cin >> a[i] >> b[i] >> c[i] >> d[i];
  10.     }
  11.     int i = 1, m = 0;
  12.     x[0] = 0, y[0] = 0, z[0] = 0;
  13.  
  14.     while (true) {
  15.         x[i] = (d[0] - (c[0] * z[i - 1]) - (b[0] * y[i - 1])) / a[0];
  16.         cout << "value of x" << i << " is " << x[i] << endl;
  17.  
  18.         double dfrnc = abs(x[i] - x[i-1]);
  19.         if(dfrnc <= eps) break;
  20.  
  21.         y[i] = (d[1] - (a[1] * x[i]) - (c[1] * z[i - 1])) / b[1];
  22.         cout << "value of y" << i << " is " << y[i] << endl;
  23.         z[i] = (d[2] - (a[2] * x[i]) - (b[2] * y[i])) / c[2];
  24.         cout << "value of z" << i << " is " << z[i] << endl;
  25.         m = i;
  26.         i++;
  27.     }
  28.     cout<< x[m] << " " << y[m] << " " << z[m] ;
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment