Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // jacobi method.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "iostream"
- using namespace std;
- int main()
- {
- int a[3][4], c[3][4], i, j, max, n, s;
- for (i = 0;i < 3;i++)
- for (j = 0;j < 4;j++) {
- cout << "[" << i + 1 << "][" << j + 1 << "] : ";
- cin >> a[i][j];
- }
- for (n = 0;n < 3;n++) {
- max = -9999;
- for(i=0;i<3;i++)
- if (a[i][n] > max) {
- max = a[i][n];
- s = i;
- }
- for (j = 0;j < 4;j++)
- c[n][j] = a[s][j];
- }
- for (i = 0;i < 3;i++) {
- for (j = 0;j < 4;j++) {
- cout << c[i][j] << " ";
- }
- cout << endl;
- }
- float x1, x2, x3, b1, b2, b3;
- b1 = b2 = b3 = 0;
- for (n = 0;n < 6;n++) {
- x1 = (c[0][3] - b2*c[0][1] - b3*c[0][2]) / c[0][0];
- x2 = (c[01][3] - b1*c[1][0] - b3*c[1][2]) / c[1][1];
- x3 = (c[2][3] - b1*c[2][0] - b2*c[2][1]) / c[2][2];
- b1 = x1;
- b2 = x2;
- b3 = x3;
- }
- cout << "x1 = " << x1 << endl << "x2 = " << x2 << endl << "x3 = " << x3 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment