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;
- x1= x2 = x3 = 0;
- for (n = 0;n < 6;n++) {
- x1 = (c[0][3] - x2*c[0][1] - x3*c[0][2]) / c[0][0];
- x2 = (c[01][3] - x1*c[1][0] - x3*c[1][2]) / c[1][1];
- x3 = (c[2][3] - x1*c[2][0] - x2*c[2][1]) / c[2][2];
- }
- cout << "x1 = " << x1 << endl << "x2 = " << x2 << endl << "x3 = " << x3 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment