1、用三个for循环
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv){
int n,m,i,j;
char ch,now;
cin>>n>>m;
for(i=0;i<n;i++){ //控制有多少行
ch='A'+i; //每行的第一个字母
for(j=0;ch!='A'&&j<m;j++,ch--){ //控制'A'前面
cout<<ch;
}
for(;j<m;j++,ch++){ //控制'A'后面
cout<<ch;
}
cout<<endl;
}
return 0;
}
2、用二维数组
字母的序号和两坐标之差的绝对值有关
#include <iostream>
#include<math.h>
using namespace std;
int main(){
//字母的序号和两坐标之差的绝对值有关
int n,m;
cin>>n>>m;
char a[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++){
a[i][j]=abs(i-j)+'A';
cout<<a[i][j];
}
cout<<endl;
}
return 0;
}
2282

被折叠的 条评论
为什么被折叠?



