Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Lesson12:

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

int RandomNumber(int From, int To)


{
//Function to generate a random number
int randNum = rand() % (To - From + 1) + From;
return randNum;
}

void PrintMatrix(int arr[3][3], short Rows, short Cols)


{
for (short R = 0; R < 3; R++)
{
for (short C = 0; C < 3; C++)
{
printf("%0*d ", 2, arr[R][C]);
}
cout << endl;
}
}

void FillMatrixWithRandomNumbers(int arr[3][3], short Rows, short Cols)


{
for (short R = 0; R < Rows; R++)
{
for (short C = 0; C < Cols; C++)
{
arr[R][C] = RandomNumber(1, 10);
}
}
}

int SumOfMatrix(int Matrix[3][3], short Rows, short Cols)


{
int Sum = 0;
for (short R = 0; R < Rows; R++)
{
for (short C = 0; C < Cols; C++)
{
Sum += Matrix[R][C];
}
}
return Sum;
}

bool AreTypicalMatrixes(int Matrix1[3][3], int Matrix2[3][3], short Rows, short Cols)


{
for (short R = 0; R < Rows; R++)
{
for (short C = 0; C < Cols; C++)
{
if (Matrix1[R][C] != Matrix2[R][C])
return false;
}
}
return true;
}

int main()
{
srand((unsigned)time(NULL));
int Matrix1[3][3], Matrix2[3][3];

FillMatrixWithRandomNumbers(Matrix1, 3, 3);
cout << "Matrix1:\n";
PrintMatrix(Matrix1, 3, 3);

FillMatrixWithRandomNumbers(Matrix2, 3, 3);
cout << "\nMatrix2:\n";
PrintMatrix(Matrix2, 3, 3);

if (AreTypicalMatrixes(Matrix1, Matrix2, 3, 3))


cout << "\nYes, matrixes are typicaly equal.\n\n";
else
cout << "\nNo, matrixes are not typicaly equal!\n\n";

return 0;
}

You might also like