Report2 행렬연산 2011, Feb 05 #include <iostream> #include <fstream> #include <cmath> #include <iomanip></p> using namespace std; //1.a+b //2.b-3a //3.(a+b)의 전치행렬 //4.ac //5.ac의 전치행렬 int A[2][3]={0,}; int B[2][3]={0,}; int C[3][2]={0,}; int AsumB[2][3]={0,}; int Bsum3A[2][3]={0,}; int AsumB_[3][2]={0,}; int AmulC[2][2]={0,}; int AmulC_[2][2]={0,}; int main(void) { ifstream fin; fin.open("input.txt"); int i=0; int j=0; int x=0; int inputx=0; int inputy=0; for(int i=0;i<3;i++) { fin>>inputx; fin>>inputy; //cout<<inputx<<" "<<inputy<<endl; for(int j=0;j<inputx;j++) { for(int x=0;x<inputy;x++) { if( i==0) fin>>A[j][x]; if( i==1) fin>>B[j][x]; if( i==2) fin>>C[j][x]; } } } cout <<"problem 1."<<endl; for(i=0;i<2;i++) { for(j=0;j<3;j++) { AsumB[i][j]=A[i][j]+B[i][j]; cout <<AsumB[i][j]<<" "; } cout <<endl; } cout <<endl; cout <<"problem 2."<<endl; for(i=0;i<2;i++) { for(j=0;j<3;j++) { Bsum3A[i][j]=B[i][j]-(3*A[i][j]); cout <<Bsum3A[i][j]<<" "; } cout <<endl; } cout <<endl; cout <<"problem 3."<<endl; for(i=0;i<3;i++) { for(j=0;j<2;j++) { AsumB_[i][j]=AsumB[j][i]; cout <<AsumB_[i][j]<<" "; } cout <<endl; } cout <<endl; cout <<"problem 4."<<endl; for(i=0;i<2;i++) { for(j=0;j<2;j++) { int temp=0; for(x=0;x<3;x++) { AmulC[i][j] = AmulC[i][j] +(A[i][x]*C[x][j]); } cout <<AmulC[i][j]<<" "; } cout <<endl; } cout <<endl; cout <<"problem 5."<<endl; for(i=0;i<2;i++) { for(j=0;j<2;j++) { AmulC_[i][j]=AmulC[j][i]; cout <<AmulC_[i][j]<<" "; } cout <<endl; } cout <<endl; return 0; } </textarea> </div> Please enable JavaScript to view the comments powered by Disqus.