i've written a program that will multiply two matrices, and as of right now it outputs the answers all in column..I was attempting to be able to output the answers in another matrix, matrix C, but I have no idea how to even get around to doing that. I did all I knew, which was to declare the matrix..other than that im stuck
...any suggestions to help me out?
my code thus far:
Code:include <iostream> //library for basic #include <math.h> using namespace std; //declare functions void matrixA(); void matrixB(); void multiply(); void validityCheck(); //declare variables int arrayB[100][100]; int i,j,num,k=1; //matrix B variables int arrayA[100][100]; int row,col,numb=1; int sum; int answer[10][10]; int main() { matrixA(); matrixB(); multiply(); } /*------------------------------My Functions----------------------------*/ void matrixA() { //creates first matrix cout<< "Matrix A "<<endl; for(i=1;i<=2;i++) { for(j=1;j<=2;j++) { arrayA[i][j]=num; num=num+1; } } for(i=1;i<=2;i++) { for(j=1;j<=2;j++) { cout.width(5); cout<<arrayA[i][j]; } cout << endl; } cout<<" "<<endl; } void matrixB() { //creates second matrix cout<< "Matrix B"<<endl; for(i=1;i<=2;i++) { for(j=1;j<=2;j++) { arrayB[i][j]=num; num=num+1; } } for(i=1;i<=2;i++) { for(j=1;j<=2;j++) { cout.width(5); cout<<arrayB[i][j]; } cout << endl; } } void multiply() { for(i=1;i<=2;i++) { for(j=1;j<=2;j++) { for(k=1;k<=2;k++) { sum=sum+(arrayA[i][k]*arrayB[k][j]); } answer[i][j]=sum; cout<<sum<<" sum "<<endl; sum=0; } } }



LinkBack URL
About LinkBacks
...any suggestions to help me out?


