// ConsoleApplication1.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include using namespace std; int main() { /* int n; cout << "n=" << endl; cin >> n; */ int n = 4; double a[4][5] = { {1,2,3,2,-1},{-1,2,2,1,0} ,{2,4,-2,2,4} ,{-1,3,2,2,0} }; for (int k = 0; k < n; k++) { int max = a[k][k]; // cout << a[k][k] << endl; int r = k; for (int i = 0; i < n; i++) { if (abs(a[i][k])>abs(max)) { max = a[i][k]; r = i; } } if (max == 0) { cout << " Macierz układu osobliwa" << endl; } for (int j = k; j < n+1 ; j++) { a[k][j] = a[r][j]; // cout << a[k][j] << endl; } for (int j = k; j < n+1; j++) { a[k][j] = a[k][j] / max; cout << k << j << endl; cout << a[k][j] << endl; } for (int i = 1; i < n; i++) { if (i == k) { continue; } for (int j = k; j < n+1; j++) { a[i][j] = a[i][j] - a[i][k] * a[k][j]; } } } for (int i = 1; i < 4; i++) { for (int j = 1; i < 5; i++) { cout << a[i][j] << endl; } } system("pause"); return 0; }