Advertisement
Dambosin

gaus

Mar 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n;
  7.     double arr[100][100];
  8.     cout<<"razmer matric"<<endl;
  9.     cin >> n;
  10.     cout<<"matrica"<<endl;
  11.     for (int i = 0; i < n; i++) {
  12.         for (int j = 0; j <= n; j++) {
  13.             cin >> arr[i][j];
  14.         }
  15.     }
  16.     for (int i = 0; i < n; i++) {
  17.         for (int j = 0; j <= n; j++) {
  18.             cout << arr[i][j] << " ";
  19.         }
  20.         cout << endl;
  21.     }
  22.     cout << endl;
  23.     double temp;
  24.     for (int i = 0; i < n; i++) {
  25.         temp = arr[i][i];
  26.         for (int j = i; j <=n; j++) {
  27.             arr[i][j] /= temp;             
  28.         }
  29.         for (int j = i+1; j < n; j++) {
  30.             temp = arr[j][i];
  31.             for (int z = i; z <= n; z++) {
  32.                 arr[j][z] -= temp * arr[i][z];
  33.             }
  34.         }
  35.     }
  36.     for (int i = 0; i < n; i++) {
  37.         for (int j = 0; j <= n; j++) {
  38.             cout << arr[i][j] << " ";
  39.         }
  40.         cout << endl;
  41.     }
  42.     double x[100];
  43.     for (int i = n - 1; i >= 0; i--) {
  44.         x[i] = arr[i][n];
  45.         for (int j = n - 1; j > i; j--) {
  46.             x[i] -= arr[i][j]*x[j];
  47.         }
  48.     }
  49.     for (int i = 0; i < n; i++) {
  50.         cout << x[i] << endl;
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement