Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <stdlib.h>
- using namespace std;
- void create_vector(double* V, int n)
- {
- int i;
- for (i=0; i<n; i++)
- {
- cout << "x[" << i<< "]= ";
- cin >> V[i];
- }
- }
- void show_vector(double* V, int n)
- {
- int i; int j;
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < 1; j++)
- cout << setw(11) << V[i];
- cout << endl;
- }
- }
- double sum_vector(double* V, int n)
- {
- int s=0;
- int i;
- for(i=0;i<n;i++)
- s=s+V[i];
- return s;
- }
- void create_matrix(double** M, int n)
- {
- int i; int j;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- {
- cout << "x[" << i << "][" << j << "] = ";
- cin >> M[i][j];
- }
- }
- void show_matrix(double** M, int n)
- {
- int i; int j;
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- cout << setw(11) << M[i][j];
- cout << endl;
- }
- }
- void mult(double**M, double* V, double* C, int n)
- {
- int i; int j;
- for(i=0;i<n;i++)
- {
- double k=0;
- for(j=0;j<n;j++)
- {
- k=k+(M[i][j]*V[j]);
- }
- C[i]=k;
- }
- }
- int main()
- {
- setlocale(LC_ALL,"Russian");
- int n; int i; int j;
- cout << "Введите размерность вектора Х: ";
- cin >> n;
- cout << endl;
- cout << "Введите элементы вектора Х:" << endl;
- double* a = new double [n];
- for(i=0;i<n;i++)
- a[i]=i;
- create_vector(a,n);
- cout << endl;
- cout << "Вектор Х:" << endl;
- show_vector(a,n);
- cout << endl;
- cout << endl;
- cout << "Сумма элементов вектора X: " << sum_vector(a,n) << endl;
- cout << endl;
- cout << endl;
- int m;
- cout << "Введите размерность матриц А и В: ";
- cin >> m;
- cout << endl;
- if(m!=n)
- {
- cout << "Ошибка!" << endl;
- cout << "Для осуществления умножения матрицы на вектор, необходимо, чтобы количество столбцов матрицы было равно количеству строк вектора!" << endl;
- system("Pause");
- return 0;
- }
- double** A = new double* [n];
- for(i=0;i<m;i++)
- A[i] = new double [n];
- cout << "Введите элементы матрицы А" << endl;
- create_matrix(A,n);
- cout << endl;
- double** B = new double* [n];
- for(i=0;i<m;i++)
- B[i] = new double [n];
- cout << "Введите элементы матрицы В" << endl;
- create_matrix(B,n);
- cout << endl;
- cout << "Матрица А:" << endl;
- show_matrix(A,n);
- cout << endl;
- cout << "Матрица B:" << endl;
- show_matrix(B,n);
- cout << endl;
- double c;
- cout << "Введите число с: ";
- cin >> c;
- cout << endl;
- double* C = new double [n];
- for(i=0; i<5; i++)
- {
- if(c >= sum_vector(a,n))
- mult(A,a,C,n);
- else
- mult(B,a,C,n);
- for(j=0; j<5; j++)
- a[j]=C[j];
- }
- cout << "Вектор Y:" << endl;
- show_vector(a,n);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement