VisualStudioC#【学习笔记020】编程练习

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014576936/article/details/80980657


编程练习

嵌套循环至少包含 2 层循环,外层的循环体执行一次,内层的循环体则执行 n 次,内层体被执行的总次数 = 内层循环次数 * 外层循环次数。

任务

要输入如下图所示图形,请用嵌套的 for 循环实现。


:::::::::::


using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
                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();//换行
            }
            //请完善代码
            
        }
    }
}

猜你喜欢

转载自blog.csdn.net/u014576936/article/details/80980657