要求:
1.1<m,n<100,输入错误要提示并退出。
2.矩阵内数据0~99,若输入越限则对此数取绝对值的末两位。
3.输入完成后清屏再按m行n列格式输出矩阵,用1或2个空格隔开数据右对齐。
4.为简便,矩阵成员多于9个时用随机数自动生成输入。
5.输出奇数行就是第0、2、4、...行;格式同3。
代码文本:
//#include "stdafx.h"//vc++ 6.0? Maybe should add this line.
#include <iostream>
#include "math.h"
#include "time.h"
using namespace std;
int main(int argc,char *argv[]){
int a[99][99],m,n,i,j;
cout << "Please enter m & n(1<m,n<100)...\n";
if((cin >> m >> n) && m>1 && n>1 && m<=N && n<=N){
if(m*n>9){
srand((unsigned)time(NULL));
for(i=0;i<m;i++)
for(j=0;j<n;a[i][j++]=rand()%100);
}
else{
cout << "Please enter the data...\n";
for(i=0;i<m;i++)
for(j=0;j<n;a[i][j++]%=100){
cin >> a[i][j];
if(a[i][j]<0)
a[i][j]=-a[i][j];
}
}
system("CLS");
cout << "You input matrix(" << m << 'x' << n << ") is as follows:\n";
for(i=0;i<m;i++){
for(j=0;j<n;cout.width(3),cout << a[i][j++]);
cout << endl;
}
cout << "This matrix odd lines output is as follows:\n";
for(i=0;i<m;i+=2){
for(j=0;j<n;cout.width(3),cout << a[i][j++]);
cout << endl;
}
}
else
cout << "Input error, exit...\n";
return 0;
}