標題:
C++ 第十四題:印出兩個 N * N 矩陣的乘積。
[打印本頁]
作者:
stephen
時間:
2010-3-13 09:49
標題:
C++ 第十四題:印出兩個 N * N 矩陣的乘積。
C++ 第十四題:印出兩個 N * N 矩陣的乘積。
作者:
yachen392
時間:
2010-3-13 10:50
/* 14 . 印出兩個N*N矩陣的乘積 */
#include<iostream>
using namespace std;
int main()
{
int n=10 ;
int a[n][n];
int b[n][n];
int c[n][n] ;
for( int i=0 ;i<n ;i++){
for( int j=0 ;j<n ;j++){
a[i][j]=(rand()%10);
cout << a[i][j] << " " ;
b[i][j]=(rand()%10);
cout << b[i][j] << " " ;
c[i][j]= a[i][j] * b[i][j];
cout << c[i][j] << endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
chuangjoy
時間:
2010-3-13 10:50
/*14.印出兩個 N * N 矩陣的乘積。*/
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void){
int n;
cout << "請輸入數字" << endl;
cin >> n;
int a[n][n];
int b[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
a[i][j] = (rand()%10);
b[i][j] = (rand()%10);
cout << a[i][j] * b[i][j] << " ";
}
cout << endl;
}
system("pause");
return 0;
}
複製代碼
作者:
p17johnny
時間:
2010-3-13 11:01
#include <iostream>
#include <cstdlib>
using namespace std;
int main (void){
int n = 10; // user input
int a[n][n];
int b[n][n];
for(int i =0; i<n; i++){
for (int j=0; j<n ; j++){
a[i][j] = (rand() % 10);
b[i][j] = (rand() % 10);
cout << a[i][j] * b[i][j]<< " ";
}
}
for(int i =0; i<n; i++){
for (int j=0; j<n ; j++){
cout <<a[i][j]<<" ";
cout <<b[i][j]<<" ";
cout << a[i][j] + b[i][j]<<" ";
}
}
system("pause");
return 0;
}
複製代碼
作者:
b1081081
時間:
2010-3-13 11:25
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void){
int n = 0;
cout << "請輸入矩陣大小:" << endl;
cin >> n;
int a[n][n];
int b[n][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
a[i][j] = (rand()%9)+1;
cout << a[i][j] << " ";
b[i][j] = (rand()%9)+1;
cout << b[i][j] << " ";
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cout << a[i][j] * b[i][j] << " ";
}
}
system("pause");
return 0;
}
複製代碼
作者:
abc3806198
時間:
2010-4-30 20:27
#include <iostream>
using namespace std;
int main(void){
int num;
cin >> num;
int a[num][num];
int b[num][num];
int c[num][num];
for( int i=0 ;i<num ;i++){
for( int j=0 ;j<num ;j++){
a[i][j]=(rand()%10);
cout << a[i][j];
b[i][j]=(rand()%10);
cout << b[i][j];
c[i][j]= a[i][j] * b[i][j];
cout << c[i][j] << endl;
}
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2