1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
实验思路:从1开始,那么最大的数就是输入的两个数的乘积,每一行的跳转的数都是列数的整数倍,且倍数从1开始递增,而且还要注意用setw()来设置下一个数据的输出域宽来保证整齐。
#include <iostream>
#include <iomanip>
using namespace std;
void Matrix(int n,int m);
int main(){
int a,b;
cout << "Please enter two integers" << endl;
cin >> a >> b;
cout << "This integer matrix is "<< endl;
Matrix(a,b);
return 0;
}
void Matrix(int n,int m){
int k = 1;
for(int i = 1; i <= n*m; i++){
cout << setw(4) << i;
if(k*m == i){
cout << endl;
k++;
}
}
return;
}