#include <iostream>
#include <cstdlib>
using namespace std;

int **init_a(int **a, int n) {
	a=new int*[n];
	for(int i=0; i<n; i++) {
		a[i]=new int [n];
	}
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			a[i][j]=rand()%6+1;
		}
	}
	return a;
}

void print_2D(int **a, int n) {
	cout<<"\n the 2d array is: "<<endl;
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			cout<<a[i][j]<<"\t";
		}
		cout<<endl;
	}
}

int numOfEl(int **a,int n) {
	int a1=0,a2=0,a3=0,a4=0,a5=0,a6=0;
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			if(a[i][j]==1)
				a1++;
			else if(a[i][j]==2)
				a2++;
			else if(a[i][j]==3)
				a3++;
			else if(a[i][j]==4)
				a4++;
			else if(a[i][j]==5)
				a5++;
			else if(a[i][j]==6)
				a6++;
		}
	}
	cout<<"\n number of times 1 shows in the 2d array: "<<a1;
	cout<<"\n number of times 2 shows in the 2d array: "<<a2;
	cout<<"\n number of times 3 shows in the 2d array: "<<a3;
	cout<<"\n number of times 4 shows in the 2d array: "<<a4;
	cout<<"\n number of times 5 shows in the 2d array: "<<a5;
	cout<<"\n number of times 6 shows in the 2d array: "<<a6<<endl;
}

int main() {
	int** a=nullptr;
	a = init_a(a,3);
	print_2D(a,3);
	numOfEl(a,3);
	return 0;
}
