Homework_5

 avatar
Alexmegawin
c_cpp
2 years ago
798 B
5
Indexable
Never
#include <iostream>
#include <time.h>
using namespace std;

int main(){
	int n, m, a = 0;
	int min = 50;
	int sum = 0;
	cout << "Enter size of massive:\n";
	cin >> n >> m;
	int** array;
	array = new int* [n];
	for (int i = 0; i < n; i++) {
		array[i] = new int[m];
	}

	srand(time(NULL));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			array[i][j] = rand()%101-50;
			cout << "| " << array[i][j] << "	|	";
			if (array[i][j] < min) {
				min = array[i][j];
			}
		}
		cout << endl ;
	}
	cout << "\nMin is " << min;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			sum += array[i][j];
		}
	}
	cout << "\nAverage is " << sum / (n * m);

	for (int h = 0; h < n; h++) {
		delete[] array[h]; 
	}
	delete[] array;
	return 0;
}