DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
矩陣é‹ç®—
// description of your code here
#include <iostream>
using namespace std;
void matIn(double mat[3][3], int r, int c)
{
int i, j;
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
cout<<"輸入M["<<i<<"]["<<j<<"]:";
cin>>mat[i][j];
}
}
}
void matSum(double mat1[3][3], double mat2[3][3], double mat3[3][3], int r, int c)
{
int i, j;
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
mat3[i][j] = mat1[i][j] + mat2[i][j];
}
}
}
void matPrint(double mat[3][3], int r, int c)
{
int i, j;
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
cout<<mat[i][j]<<" ";
cout<<endl;
}
}
void main()
{
double mat1[3][3], mat2[3][3], mat3[3][3];
cout<<"輸入第一個矩陣:\n";
matIn(mat1, 3, 3);
cout<<"輸入第二個矩陣:\n";
matIn(mat2, 3, 3);
matSum(mat1, mat2, mat3, 3, 3);
cout<<"陣列åˆç‚ºä¸‹\n";
matPrint(mat3, 3, 3);
cout<<endl;
system("pause");
}





