C++ part 7 (2/2) – Basic matrix operations (From mathematical point of view)

In this post I will gradually add basic mathematical functions that have matrix operations in them. Below is the code for a simple addition of two matrices.

#include <iostream>
using namespace std;
int main()
{

int a[2][2] = {{2,3},
{4,5}};

int b[2][2] = {{5,2},
{9,7}};

int matrix[2][2];

for(int i = 0; i < 2; i++) {
for(int d = 0; d < 2; d++) {
matrix[i][d] = a[i][d] + b[i][d];
cout << matrix[i][d] << endl;
}
}

system(“PAUSE”);
return 0;
}

s

 

and here is the logic behind it

math

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s