代码
for (int x = 1; x <= 7; x++)//循环7行
{
for (int y = 1; y <= 7; y++)//循环7列
{
if (x == y || x + y == 8)//对角线打印O
{
Console.Write("O");
}
else
{
Console.Write(".");//其他位置打印.
}
}
Console.WriteLine();//换行
}
先不要慌着写代码,写代码之前先用伪代码构思算法和结构:例如:
const n = 7
for(y =1~n){
for(x =1~n){
if(x==y || x==n-y+1){
output(0);
}
output(*);
}
Change line;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test01
{
class Program
{
static void Main(string[] args)
{
const int n = 7;
for (int y = 1; y <= n; y++)
{
for (int x = 1; x <= n; x++)
{
if (x == y || x == n - y + 1)
{
Console.Write("O");
}
else
{
Console.Write(".");
}
}
Console.WriteLine();
}
}
}
}