为了账号安全,请及时绑定邮箱和手机立即绑定

正在回答

3 回答

 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();//换行
            }

1 回复 有任何疑惑可以回复我~

先不要慌着写代码,写代码之前先用伪代码构思算法和结构:例如:

const n = 7

for(y =1~n){

  for(x =1~n){

    if(x==y || x==n-y+1){

     output(0);

    }

    output(*);

  }

  Change line;


0 回复 有任何疑惑可以回复我~

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();

            }

        }

    }

}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
C#开发轻松入门
  • 参与学习       251680    人
  • 解答问题       1448    个

本门课程是C#语言的入门教程,将带你轻松入门.NET开发

进入课程

c#小白,跪求大神给

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信