用for循环做了一下又想用数组做一下
#include <iostream>
using namespace std;
void main(){
int i=0,m=5;
char sz[9][9]={0};
for(;i<=8;i++){
if(i<=4){
for(int k=0;k<=i;k++){
sz[i][m-k]=sz[i][m+k]='*';}
}
if(i>4){
for(int o=8-i;o>=0;o--){
sz[i][m-o]=sz[i][m+o]='*';}
}
}
for(int t=1;t<=9;t++){
for(int y=1;y<=9;y++){
cout<<sz[t][y];}
cout<<'\n';
}
}
但是结果产生了乱码
自己没找到错误,初学者求助
char sz[9][9]={0};
数组下标范围是0-8
你越界了
#include
using namespace std;
int main(){
cout << " * " << endl;
cout << " * * * " << endl;
cout << " * * * * * " << endl;
cout << " * * * * * * * " << endl;
cout << "* * * * * * * * *" << endl;
cout << " * * * * * * * " << endl;
cout << " * * * * * " << endl;
cout << " * * * " << endl;
cout << " * " << endl;
return 0;
}