Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include <cstdlib>
- using namespace std;
- int Sorting()
- {
- int* arr;
- int size;
- cout << "n = ";
- cin >> size;
- arr = new int[size];
- for (int i = 0; i < size; i++) {
- arr[i] = rand() % 100 + 1;
- }
- cout << "no sort:" << endl;
- for (int i = 0; i < size; i++) {
- cout << arr[i] << " ";
- }
- int temp;
- for (int i = 0; i < size - 1; i++) {
- for (int j = 0; j < size - i - 1; j++) {
- if (arr[j] > arr[j + 1]) {
- temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = temp;
- }
- }
- }
- cout << "\nsort: " << endl;
- for (int i = 0; i < size; i++) {
- cout << arr[i] << " ";
- }
- cout << endl;
- return 0;
- }
- int Matrix_multiplication()
- {
- int row1, row2, col1, col2;
- double** a, **b, **c;
- cout << "row1: ";
- cin >> row1;
- cout << "col1: ";
- cin >> col1;
- cout << "row2: ";
- cin >> row2;
- cout << "col2: ";
- cin >> col2;
- if (col1 != row2)
- {
- cout << "multiplication is not possible!";
- cin.get(); cin.get();
- return 0;
- }
- // эл. первой матрицы. ввод
- a = new double* [row1];
- cout << "elements 1" << endl;
- for (int i = 0; i < row1; i++)
- {
- a[i] = new double[col1];
- for (int j = 0; j < col1; j++)
- {
- cout << "a[" << i << "][" << j << "]= ";
- cin >> a[i][j];
- }
- }
- // эл. первой матрицы. вывод
- for (int i = 0; i < row1; i++)
- {
- for (int j = 0; j < col1; j++)
- cout << a[i][j] << " ";
- cout << endl;
- }
- // эл. второй матрицы. ввод
- b = new double* [row2];
- cout << "elements 2" << endl;
- for (int i = 0; i < row2; i++)
- {
- b[i] = new double[col2];
- for (int j = 0; j < col2; j++)
- {
- cout << "b[" << i << "][" << j << "]= ";
- cin >> b[i][j];
- }
- }
- // эл. второй матрицы. вывод
- for (int i = 0; i < row2; i++)
- {
- for (int j = 0; j < col2; j++)
- {
- cout << b[i][j] << " ";
- }
- cout << endl;
- }
- // Умножение
- c = new double* [row1];
- for (int i = 0; i < row1; i++)
- {
- c[i] = new double[col2];
- for (int j = 0; j < col2; j++)
- {
- c[i][j] = 0;
- for (int k = 0; k < col1; k++)
- c[i][j] += a[i][k] * b[k][j];
- }
- }
- // Вывод матрицы произведения
- cout << "result" << endl;
- for (int i = 0; i < row1; i++)
- {
- for (int j = 0; j < col2; j++)
- cout << c[i][j] << " ";
- cout << endl;
- }
- cin.get(); cin.get();
- return 0;
- }
- int Solve_integral1()
- {
- double a = 0;
- double b = M_PI/2;
- int n = 2;
- double h = (b - a) / n;
- double c = a + h;
- double result = 0;
- result += (pow(cos(3 * a), 3) * sin(6 * a));
- for (int i = 0; i < n; i++)
- {
- result += h*(pow(cos(3 * c), 3) * sin(6 * c));
- c += h;
- }
- cout << "метод прямоугольников:" << endl;
- cout << result << endl;
- c = a + h;
- result = ((pow(cos(3 * a), 3) * sin(6 * a))+
- (pow(cos(3 * b), 3) * sin(6 * b)))/2;
- for (int i = 0; i < n; i++)
- {
- result += (pow(cos(3 * c), 3) * sin(6 * c));
- c += h;
- }
- result *= h;
- cout << "метод трапеций:" << endl;
- cout << result << endl;
- return 0;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- cout << "Что будем делать?\n1. Умножение матриц\n2. Умножение вектора на матрицу \n3. Сортировка \n4. Интегралы" << endl;
- int choise = 0;
- cin >> choise;
- if (choise == 1 || choise == 2)
- {
- Matrix_multiplication();
- }
- if (choise == 3)
- {
- Sorting();
- }
- if (choise == 4)
- {
- Solve_integral1();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement