C#输出从0开始累加到输入的目标数之和的式子

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

namespace KnowledgePoint
{
    class _17_Ex_For
    {
        static void Main(string[] args)
        {
            Console.Write("请输入一个目标数:");
            try
            {
                int targetNum = Convert.ToInt32(Console.ReadLine());
                for (int i = 0; i <= targetNum; i++)
                {
                    Console.WriteLine("{0} + {1} = {2}", i, (targetNum - i), targetNum);
                } // for循环结束
            }
            catch
            {
                Console.WriteLine("\n提示:数字格式异常!");
            } // try-catch结束

            Console.ReadKey();
        }
    }
}

你可能感兴趣的:(典化成籍-C#,C#,for,格式输出)