Advertisement
LordMirai

triunghiulare

Apr 13th, 2021
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1.  
  2. void Triunghiulare() {
  3.     int n = INT_MIN;
  4.     double a[100][100], b[100], S, x[100];
  5.     cout << "Introd n.\nn = "; cin >> n;
  6.     for (int i = 1; i <= n; i++)
  7.     {
  8.         for (int j = 1; j <= n; j++)
  9.         {
  10.             cout << "a[" << i << "][" << j << "] = ";
  11.             cin >> a[i][j];
  12.         }
  13.     }
  14.     for (int i = 1; i <= n; i++)
  15.     {
  16.         cout << "b[" << i << "] = ";
  17.         cin >> b[i];
  18.     }
  19.     for (int i = n; i >= 1; i--)
  20.     {
  21.         S = 0;
  22.         for (int j = i + 1; j <= n; j++)
  23.         {
  24.             S = S + a[i][j] * x[j];
  25.         }
  26.         x[i] = (b[i] - S) / a[i][i];
  27.     }
  28.     cout << endl;
  29.     for (int i = 1; i <= n; i++)
  30.     {
  31.         cout << "x[" << i << "] = " << x[i] << " ";
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement