Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctime>
- using namespace std;
- void createMatr(int**&, int );
- void input(int**, int);
- void output(int**, int);
- int SUM(int**, int);
- int result(int, int, int);
- int n, sum_A, sum_B, sum_C;
- int** A, **B, **C;
- int main()
- {
- srand(time(NULL));
- cout << "Enter n: ";
- cin >> n; cout << endl;
- createMatr(A, n);
- createMatr(B, n);
- createMatr(C, n);
- input(A, n);
- input(B, n);
- input(C, n);
- output(A, n);
- sum_A = SUM(A, n);
- output(B, n);
- sum_B = SUM(B, n);
- output(C, n);
- sum_C = SUM(C, n);
- cout <<"result: "<< result(sum_A, sum_B, sum_C)<<endl;
- system("pause");
- return 0;
- }
- void createMatr(int**& Matr, int n) {
- Matr = new int*[n];
- for (int i = 0; i < n; i++)
- Matr[i] = new int[n];
- };
- void input(int** Matr, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- Matr[i][j] = rand() % 10;
- }
- }
- };
- void output(int** Matr, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- printf("%2d", Matr[i][j]);
- };
- cout << endl;
- }
- cout << endl;
- };
- int SUM(int** Matr, int n) {
- int sum = 0;
- for (int i = 0; i < n; i++) {
- for (int j = i; j < n; j++) {
- sum += Matr[i][j];
- }
- }
- cout << "sum is: " << sum << endl<<endl;
- return sum;
- }
- int result(int a, int b, int c) {
- return((a + b + c) / 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement