Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define eps 0.000000001
- using namespace std;
- int main() {
- double a[10], b[10], c[10], d[10], x[10], y[10], z[10];
- cout << "Enter coefficients of 3 variable equation\n";
- for (int i = 0; i < 3; i++) {
- cin >> a[i] >> b[i] >> c[i] >> d[i];
- }
- int i = 1, m = 0;
- x[0] = 0, y[0] = 0, z[0] = 0;
- while (true) {
- x[i] = (d[0] - (c[0] * z[i - 1]) - (b[0] * y[i - 1])) / a[0];
- cout << "value of x" << i << " is " << x[i] << endl;
- double dfrnc = abs(x[i] - x[i-1]);
- if(dfrnc <= eps) break;
- y[i] = (d[1] - (a[1] * x[i]) - (c[1] * z[i - 1])) / b[1];
- cout << "value of y" << i << " is " << y[i] << endl;
- z[i] = (d[2] - (a[2] * x[i]) - (b[2] * y[i])) / c[2];
- cout << "value of z" << i << " is " << z[i] << endl;
- m = i;
- i++;
- }
- cout<< x[m] << " " << y[m] << " " << z[m] ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment