ex05-06.cpp
来自「在c环境下的对数据结构进行讲解,包含有例题及答案」· C++ 代码 · 共 50 行
CPP
50 行
//EX05-06.cpp
#include <iostream.h> //cout,cin
#include <conio.h> // getch()
#include <stdlib.h> //random
const int M=5;
const int N=4;
const int P=3;
void main()
{ int a[M][N],b[N][P],c[M][P],i,j;
for (i=0;i<M;i++) //get a data
for (j=0;j<N;j++)
a[i][j]=random(10); //get random data
for (i=0;i<N;i++) //get b data
for (j=0;j<P;j++)
b[i][j]=random(10); //get random data
cout << "a array as followings:\n";
for (i=0;i<M;i++)
{ for (j=0;j<N;j++)
{ cout.width(3);
cout<<a[i][j];
}
cout << endl;
}
cout << "b array as followings:\n";
for (i=0;i<N;i++)
{ for (j=0;j<P;j++)
{ cout.width(3);
cout<<b[i][j];
}
cout << endl;
}
// do the product
for (i=0;i<M;i++)
for (j=0;j<P;j++)
{ c[i][j]=0;
for (int k=0;k<N;k++)
c[i][j]+=a[i][k]*b[k][j];
}
cout << "c array as followings:\n";
for (i=0;i<M;i++)
{ for (j=0;j<P;j++)
{ cout.width(5);
cout<<c[i][j];
}
cout << endl;
}
getch();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?