Advertisement
Guest User

asdfsadfa

a guest
Feb 20th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <cmath>
  3. #include <iomanip>
  4. #include "iostream"
  5. #include <ctime>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. void arr_input(int **x, int M, int N)
  11. {
  12.     cout << "Ввод массива" << endl;
  13.     for (int i = 0; i < M; ++i)
  14.     {
  15.         for (int j = i; j < N; ++j)
  16.         {
  17.             cin >> x[i][j];
  18.         }
  19.         cout << endl;
  20.     }
  21.  
  22. }
  23.  
  24. void arr_output(int **x, int M, int N)
  25. {
  26.     system("cls");
  27.     cout << "Вывод массива" << endl << endl;
  28.     for (int i = 0; i < M; ++i)
  29.     {
  30.         for (int j = 0; j < i; ++j)
  31.         {
  32.             cout << setw(4) << " ";
  33.         }
  34.         for (int j = i; j < N; ++j)
  35.         {
  36.             cout << setw(4) << x[i][j];
  37.         }
  38.         cout << endl;
  39.     }
  40. }
  41.  
  42. void arr_input_rand(int **x, int M, int N)
  43. {
  44.     cout << "Ввод массива" << endl;
  45.     for (int i = 0; i < M; ++i)
  46.     {
  47.         for (int j = i; j < N; ++j)
  48.         {
  49.             x[i][j] = rand() % 150;
  50.         }
  51.         cout << endl;
  52.     }
  53.  
  54. }
  55.  
  56. int **arr_create(unsigned int str, unsigned int stl) {
  57.     int **ptrary = new int *[str];
  58.     for (int i = 0; i < str; i++) {
  59.         ptrary[i] = new int[stl];
  60.     }
  61.     return ptrary;
  62. }
  63.  
  64. bool elements_0(int *x, int N)
  65. {
  66.     int count;
  67.     for (int i = 0; i < N; ++i)
  68.     {
  69.         if (x[i] != 0) { return false; }
  70.     }
  71.     return true;
  72. }
  73.  
  74. int strings_0(int **x, int M, int N)
  75. {
  76.     int count = 0;
  77.     for (int i = 0; i < M; ++i)
  78.     {
  79.         if (elements_0(x[i], N)) { ++count; }
  80.     }
  81.     return count;
  82. }
  83.  
  84. double intToDoub(int h)
  85. {
  86.     double x = h;
  87.     return x;
  88.  
  89. }
  90.  
  91. double find_x(int chisl, int znam)
  92. {
  93.     double res = intToDoub(chisl) / intToDoub(znam);
  94.     return res;
  95. }
  96.  
  97. void sss(int **x, int M, int N)
  98. {
  99.     int sum = 0;
  100.     vector <double> xs(N);
  101.     int m = M - 1, n = N - 1;
  102.     cout << "m = " << m << "n = " << n;
  103.    
  104.     int sas = n;
  105.     for (int i = m; i >= 0; --i)
  106.     {
  107.         for (int j = n - 1; j != i; --j)
  108.         {
  109.             sum -= x[i][j] * xs[j];
  110.         }
  111.         sum += x[i][n];
  112.         xs[sas] = find_x(sum, x[i][i]);
  113.         sum = 0;
  114.         --sas;
  115.     }
  116.  
  117.     for (int i = 0; i < xs.size(); ++i)
  118.     {
  119.         cout << xs[i] << " ";
  120.     }
  121. }
  122.  
  123. int main()
  124. {
  125.     setlocale(0, "");
  126.     int **mt;
  127.     int str, stl;
  128.     cout << "Введите размер матрицы: " << endl;
  129.     cin >> str;
  130.     stl = str+1;
  131.     mt = arr_create(str, stl);
  132.     int k;
  133.     cout << "1 - вручную, 0 - случайные значения" << endl;
  134.     cin >> k;
  135.     if (k == 1) { arr_input(mt, str, stl); }
  136.     if (k == 0) { arr_input_rand(mt, str, stl); }
  137.  
  138.     arr_output(mt, str, stl);
  139.     sss(mt, str, stl);
  140.  
  141.     //cout << strings_0(mt,str,stl);
  142.  
  143.  
  144.     cout << endl;
  145.  
  146.     return 0;
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement