C++ Matrix Multiplication
// matrix.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//Here i am using a two dimensional arrayof size 2 you can use array of any size.
//Also you can input values in array here i am giving values at compile time.
int A[2][2]={1,2,3,4};
int B[2][2]={4,3,2,1};
int C[2][2];
int i, j, k;
int sum;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
sum = 0;
for (k = 0; k < 2; k++)
{
sum += A[i][k] * B[k][j];
}
C[i][j] = sum;
cout<<"result is"<<sum<<endl;
}
}
return 0;
}
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//Here i am using a two dimensional arrayof size 2 you can use array of any size.
//Also you can input values in array here i am giving values at compile time.
int A[2][2]={1,2,3,4};
int B[2][2]={4,3,2,1};
int C[2][2];
int i, j, k;
int sum;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
sum = 0;
for (k = 0; k < 2; k++)
{
sum += A[i][k] * B[k][j];
}
C[i][j] = sum;
cout<<"result is"<<sum<<endl;
}
}
return 0;
}
Comments
Post a Comment