C#一个小图形

来源:百度知道 编辑:UC知道 时间:2024/05/17 05:23:55
for (int i=1;i<=7;i++)
{

Console.Write("*");
for (int j=1;j<=8;j++)
{

}
}

让第一个for 控制行 第2个 for 控制列
显示出一个树形

000*000
00***00
0*****0
*******
00***00
00***00
00***00

0 代表空格

int rows = 9;
int cols = rows * 2 - 1;
int cnt = cols/2;
for(int i=0; i<rows; i++) {
for(int j=0; j<cols; j++) {
if(i+j < cnt || j-i > cnt) {
System.Console.Write(" ");
}
else {
System.Console.Write("*");
}
}
System.Console.WriteLine();
}
for(int i=0; i<3; i++) {
for(int j=0; j<cols; j++) {
if(j < rows -2 || j > rows) {
System.Console.Write(" ");
}
else {
System.Console.Write("*");
}
}
System.Console.WriteLine();
}
System.Console.ReadLine();

rows表示三角形的行,想画多少花多少