Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. // AlgorytmGaussa.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. void b()
  8. {
  9.     const int n = 4;
  10.     //double A[n][n] = { { 10, 1, 1, 1, 2 },{ 3, 20, 4, 2, 1 },{ 5, 1, 40, 9, 5 },{ 3, 0, 1, 10, 1 },{ 6, 2, 1, 1, 20 } };
  11.     //double B[n] = { 15, 30, 60, 15, 30 };
  12.  
  13.     double A[n][n] = { { 1, 2, 3, 4 },{ 2, 5, 10, 15 },{ 3, 10, 20, 30 },{ 1, 5, 20, 30 } };
  14.     double B[n] = { 10, 32, 63, 52 };
  15.  
  16.     for (int k = 0; k <= n - 2; k++)
  17.     {
  18.         double tmp = A[k][k];
  19.         if (tmp == 0)
  20.             break;
  21.         else
  22.         {
  23.  
  24.             for (int i = k; i <= n - 1; i++)
  25.             {
  26.                 for (int j = k; j <= n - 1; j++)
  27.                 {
  28.                     A[i][j] = A[i][j] - (A[i][k] * A[k][j] / tmp);
  29.                 }
  30.  
  31.                 B[i] = B[i] - (A[i][k] * B[k] /tmp);
  32.             }
  33.         }      
  34.     }
  35.     int p = 0;
  36. }
  37.  
  38. int main()
  39. {
  40.     b();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement