Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int getRandCellValue() {
- double randValue = (double) rand() / RAND_MAX;
- return 270 * randValue - 120;
- }
- void fillMatrix(int a[30][30], int n, int m) {
- int i, j;
- for (i = 0; i < n; ++i)
- for (j = 0; j < m; ++j)
- a[i][j] = getRandCellValue();
- }
- void writeMatrix(int a[30][30], int n, int m) {
- int i, j;
- for (i = 0; i < n; ++i) {
- for (j = 0; j < m; ++j)
- cout << a[i][j] << ' ';
- cout << endl;
- }
- }
- void sumMatrix(int a[30][30], int b[30][30], int c[30][30], int n, int m) {
- int i, j;
- for (i = 0; i < n; ++i)
- for (j = 0; j < m; ++j)
- c[i][j] = a[i][j] + b[i][j];
- }
- int main() {
- setlocale(0, "");
- srand(time(0));
- int a[30][30], b[30][30], c[30][30];
- int n, m;
- cout << "Введите количество строк: ";
- cin >> n;
- cout << "Введите количество столбцов: ";
- cin >> m;
- fillMatrix(a, n, m);
- fillMatrix(b, n, m);
- cout << "Матрица А:" << endl;
- writeMatrix(a, n, m);
- cout << "Матрица B:" << endl;
- writeMatrix(b, n, m);
- sumMatrix(a, b, c, n, m);
- cout << "Матрица A+B:" << endl;
- writeMatrix(c, n, m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement