VB icon

Matrix Multiplication

Email
Submitted on: 1/2/2015 12:58:00 AM
By: Jeff Wurz (from psc cd)  
Level: Intermediate
User Rating: By 6 Users
Compatibility: C++ (general)
Views: 416
 
     It takes a user inputed matrix and multiplys it by another user inputed matrix producing a matrix...
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Matrix Multiplication
//**************************************
#include <iostream.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Matrix Multiplication
// Description:It takes a user inputed matrix and multiplys it by another user inputed matrix producing a matrix...
// By: Jeff Wurz (from psc cd)
//
// Side Effects:can get some warnings in compilers... its just cause of the way i had to program it... the reinitializing of the matrices
//**************************************

#include <iostream.h>
	
int main()
{
int cols = 3, rows= 2, colss= 2, rowss= 3;
int var = 0;
cout << "Enter in the number or rows for the first matrix: ";
cin >> cols;
cout << "Enter in the number or columns for the first matrix: ";
cin >> rows;
	int mat[2][2];
	mat[rows-1][cols-1];
	for(int row = 0; row <= rows-1; row++)
		{
		for(int col = 0; col <= cols-1; col++)
			{
			cout << "Enter the value for the element of row " << row + 1 << " and column " << col + 1 << " of the first matrix: ";
			cin >> var;
			mat[row][col] = var;
			cout << '\n';
			}
		}
cout << "Enter in the number or rows for the second matrix: ";
cin >> colss;
cout << "Enter in the number or columns for the second matrix: ";
cin >> rowss;
	int matr[2][2];
	matr[rowss-1][colss-1];
	for(row = 0; row <= rowss-1; row++)
		{
		for(int col = 0; col <= colss-1; col++)
			{
			cout << "Enter the value for the element of row " << row + 1<< " and column " << col + 1<< " of the second matrix: ";
			cin >> var;
			matr[row][col] = var;
			cout << '\n';
			}
		}
int matri[2][2];
matri[rows][rowss];
matri[1][0]	= 0;
int vect[2];
for(int xvar = 0; xvar <= rows; xvar++)
	{
	for(int yvar = 0; yvar <= cols; yvar++)
		{
		for(int xvari = 0; xvari <= rowss; xvari++)
			{
		for(int yvari = 0; yvari <= colss; yvari++)
				{
			vect[yvar] = mat[xvar][yvar] * matr[yvari][xvari];
				}
			}
		}
	for(int vecto = 0; vecto <= rows; vecto++)
		{
			for(int xvect = 0; xvect <= rows; xvect++)
			{
			for(int yvect = 0; yvect <= rows; yvect++)
				{
				matri[xvect][yvect] = vect[vecto];
				}
			}
		}
	
	} 
	
	cout << "\n";
	for (rows = 0; rows < 2; rows++)
	{
		for (cols = 0; cols < 2; cols++)
		{
			cout << matri[rows][cols] << " ";
		}
		cout << endl;
	}
return 0;
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.