Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <typename T>
- void createMas(T**& mas, int n) {
- mas = new T * [n];
- for (int i = 0; i < n; ++i) {
- mas[i] = new T[n];
- for (int j = 0; j < n; ++j) {
- cin >> mas[i][j];
- }
- }
- }
- template <typename T>
- void printMas(T** mas, int n) {
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- cout << mas[i][j] << " ";
- }
- cout << endl;
- }
- }
- template <typename T>
- double averageAriphm(T** mas, int n) {
- int cnt = 0;
- double av_sum = 0;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (j > i) {
- cnt++;
- av_sum += mas[i][j];
- }
- }
- }
- av_sum /= cnt;
- return av_sum;
- }
- template <typename T>
- void deleteMas(T** mas, int n) {
- for (int i = 0; i < n; ++i) {
- delete[] mas[i];
- }
- delete[] mas;
- }
- int main() {
- int** a;
- int n1;
- cin >> n1;
- createMas(a, n1);
- double** b;
- int n2;
- cin >> n2;
- createMas(b, n2);
- cout << averageAriphm(a, n1) << " " << averageAriphm(b, n2) << endl;
- cout << endl;
- printMas(a, n1);
- printMas(b, n2);
- deleteMas(a, n1);
- deleteMas(b, n2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement