Ví dụ:
[Code Turbo C++]
#include <conio.h>
#include <iostream.h>
#define max 100
float A[max][max]; // khai bao ma tran A
/*Nhap ma tran he so*/
void NhapMaTran(int m, int n) {
for(int i = 0; i<m; i++)
for(int j = 0; j<n; j++) {
cout<<"a["<<i<<"]["<<j<<"] = ";
cin>>A[i][j];
}
}
/*Xuat ma tran*/
void XuatMaTran(int m, int n) {
for(int i=0 ; i<m; i++){
cout<<endl;
for(int j=0 ; j<n; j++)
cout<<A[i][j]<<"\t";
}
}
/*Chuong trinh chinh*/
void main() {
int m, n;
clrscr();
// nhap kich thuoc ma tran
do{
cout<<"Nhap so dong m = ";
cin>>m;
if (m<1||m>max) cout<<"\n nhap lai m";
}while(m<1||m>max);
do{
cout<<"Nhap so dong n = ";
cin>>n;
if (n<1||n>max) cout<<"\n nhap lai n";
}while(n<1||n>max);
cout<<"\nNhap ma tran A cap "<<m<<"x"<<n<<endl;
NhapMaTran(m,n);
cout<<"\nXuat ma tran A";
XuatMaTran(m,n);
getch();
}
0 nhận xét:
Đăng nhận xét