Facebook
From dasda, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 297
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. /*      int n;
  13.         cout << "n=" << endl;
  14. cin >> n; */
  15.         int n = 4;
  16.         double a[4][5] = { {1,2,3,2,-1},{-1,2,2,1,0} ,{2,4,-2,2,4} ,{-1,3,2,2,0} };
  17.         for (int k = 0; k < n; k++)
  18.         {
  19.                 int max = a[k][k];
  20.         //      cout << a[k][k] << endl;
  21.                 int r = k;
  22.                 for (int i = 0; i < n; i++)
  23.                 {
  24.  
  25.                         if (abs(a[i][k])>abs(max)) {
  26.                                 max = a[i][k];
  27.                                 r = i;
  28.                         }
  29.                 }
  30.                 if (max == 0) {
  31.                         cout << " Macierz układu osobliwa" << endl;
  32.                 }
  33.                 for (int j = k; j < n+1 ; j++) {
  34.                         a[k][j] = a[r][j];
  35.                 //      cout << a[k][j] << endl;
  36.                 }
  37.                 for (int j = k; j < n+1; j++)
  38.                 {
  39.                         a[k][j] = a[k][j] / max;
  40.                         cout << k << j << endl;
  41.                         cout << a[k][j] << endl;
  42.                 }
  43.                 for (int i = 1; i < n; i++) {
  44.                         if (i == k) {
  45.                                 continue;
  46.                         }
  47.                         for (int j = k; j < n+1; j++)
  48.                         {
  49.                                 a[i][j] = a[i][j] - a[i][k] * a[k][j];
  50.                         }
  51.                 }
  52.  
  53.         }
  54.         for (int i = 1; i < 4; i++)
  55.         {
  56.                 for (int j = 1; i < 5; i++)
  57.                 {
  58.                         cout << a[i][j] << endl;
  59.                 }
  60.         }
  61.  
  62.         system("pause");
  63.     return 0;
  64.  
  65. }
  66.  
  67.  
  68.