用C#输出9*9乘法表

采用VS 2017编程 

Console.Write()输出的是string类型,整型 加上一个字符串,整行语句会自动变成字符串类型,和Java一样

考虑到乘法表是从 每一行的第一个因数从1递增到9,第二个因素从1递增到第一个因数,采用双循环即可完成

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;  //i为第一个因数,j为第二个因数
            for(i = 1; i <= 9; i++)   //i从1递增到9
            {
                for(j=1; j <= i; j++)  //j从1递增到i
                {
                    Console.Write(i + "*" + j +"="+ i * j + '\t');
                }
                Console.Write("\n");
            }

            Console.ReadKey();  //防止程序一闪而过
        }
    }
}

                              

猜你喜欢

转载自blog.csdn.net/weixin_38125348/article/details/82389054