#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

#define N 100

void mult1(int **a, int **b, int **c)
{
	for (unsigned q=0; q<N; ++q)
		for (unsigned w=0; w<N; ++w)
			c[q][w] = 0;
			
	for (unsigned q=0; q<N; ++q)
		for (unsigned w=0; w<N; ++w)
			for (unsigned e=0; e<N; ++e)
				c[q][w] += a[q][e] * b[e][w];
}

void mult2(int **a, int **b, int **c)
{
	for (unsigned q=0; q<N; ++q)
		for (unsigned w=0; w<N; ++w)
			c[q][w] = 0;
			
	for (unsigned q=0; q<N; ++q)
		for (unsigned w=0; w<N; ++w)
			for (unsigned e=0; e<N; ++e)
				c[q][w] += a[q][e] * b[w][e];
}

int main()
{
	int **a = new int*[N];
	int **b = new int*[N];
	int **c = new int*[N];
	
	for (unsigned q=0; q<N; ++q)
	{
		a[q] = new int[N];
		b[q] = new int[N];
		c[q] = new int[N];
		
		for (unsigned w=0; w<N; ++w)
		{
			a[q][w] = rand();
			b[q][w] = rand();
		}
	}
	
	long m1=0, m2=0;
	
	for (unsigned q=0; q<10; ++q)
	{
		long t = clock();
		mult1(a, b, c);
		m1 += t = clock() - t;
		cout << "1: " << t << endl;
		
		t = clock();
		mult2(a, b, c);
		m2 += t = clock() - t;
		cout << "2: " << t << endl;
	}
	
	cout << endl << "Results: " << m1 << ", " << m2 << endl;
	
	return 0;
}