Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <cmath>
- #include <iomanip>
- #include "iostream"
- #include <ctime>
- #include <vector>
- using namespace std;
- void arr_input(int **x, int M, int N)
- {
- cout << "Ввод массива" << endl;
- for (int i = 0; i < M; ++i)
- {
- for (int j = i; j < N; ++j)
- {
- cin >> x[i][j];
- }
- cout << endl;
- }
- }
- void arr_output(int **x, int M, int N)
- {
- system("cls");
- cout << "Вывод массива" << endl << endl;
- for (int i = 0; i < M; ++i)
- {
- for (int j = 0; j < i; ++j)
- {
- cout << setw(4) << " ";
- }
- for (int j = i; j < N; ++j)
- {
- cout << setw(4) << x[i][j];
- }
- cout << endl;
- }
- }
- void arr_input_rand(int **x, int M, int N)
- {
- cout << "Ввод массива" << endl;
- for (int i = 0; i < M; ++i)
- {
- for (int j = i; j < N; ++j)
- {
- x[i][j] = rand() % 150;
- }
- cout << endl;
- }
- }
- int **arr_create(unsigned int str, unsigned int stl) {
- int **ptrary = new int *[str];
- for (int i = 0; i < str; i++) {
- ptrary[i] = new int[stl];
- }
- return ptrary;
- }
- bool elements_0(int *x, int N)
- {
- int count;
- for (int i = 0; i < N; ++i)
- {
- if (x[i] != 0) { return false; }
- }
- return true;
- }
- int strings_0(int **x, int M, int N)
- {
- int count = 0;
- for (int i = 0; i < M; ++i)
- {
- if (elements_0(x[i], N)) { ++count; }
- }
- return count;
- }
- double intToDoub(int h)
- {
- double x = h;
- return x;
- }
- double find_x(int chisl, int znam)
- {
- double res = intToDoub(chisl) / intToDoub(znam);
- return res;
- }
- void sss(int **x, int M, int N)
- {
- int sum = 0;
- vector <double> xs(N);
- int m = M - 1, n = N - 1;
- cout << "m = " << m << "n = " << n;
- int sas = n;
- for (int i = m; i >= 0; --i)
- {
- for (int j = n - 1; j != i; --j)
- {
- sum -= x[i][j] * xs[j];
- }
- sum += x[i][n];
- xs[sas] = find_x(sum, x[i][i]);
- sum = 0;
- --sas;
- }
- for (int i = 0; i < xs.size(); ++i)
- {
- cout << xs[i] << " ";
- }
- }
- int main()
- {
- setlocale(0, "");
- int **mt;
- int str, stl;
- cout << "Введите размер матрицы: " << endl;
- cin >> str;
- stl = str+1;
- mt = arr_create(str, stl);
- int k;
- cout << "1 - вручную, 0 - случайные значения" << endl;
- cin >> k;
- if (k == 1) { arr_input(mt, str, stl); }
- if (k == 0) { arr_input_rand(mt, str, stl); }
- arr_output(mt, str, stl);
- sss(mt, str, stl);
- //cout << strings_0(mt,str,stl);
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement