Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- void fill_in(int** a, const int N, const int M, ifstream& file)
- {
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < M; j++)
- {
- file >> a[i][j];
- cout << a[i][j] << "\t";
- }
- cout << endl;
- }
- }
- void print(int** a, const int N, const int M)
- {
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < M; j++)
- {
- cout << a[i][j] << "\t";
- }
- cout << endl;
- }
- }
- double arifm_nadgl(int** a, int n, int m)
- {
- double summ = 0; int k = 0;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (i < j)
- {
- summ += a[i][j];
- k++;
- }
- }
- }
- return summ / k;
- }
- int main()
- {
- setlocale(0, "Rus");
- ifstream file("J:\\Универ\\Программирование\\Практика_txt\\z_12.txt");
- if (file.is_open())
- {
- int N = 10, M = 10;
- int** A;
- A = new int* [N];
- for (int i = 0; i < N; i++)
- A[i] = new int[M];
- cout << "Матрица A: " << endl;
- fill_in(A, N, M, file);
- cout << "Среднее арифметическое: " << arifm_nadgl(A, N, M) << endl;
- system("pause");
- return 0;
- }
- else
- {
- cout << "Файл не открыт" << endl;
- system("pause");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement