實驗簡述:
2. 自定義一個整數,輸出該數分別於1-10相乘的結果。(使用\t控制輸出格式)
源代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Consoletest1
{
class Program
{
static void Main(string[] args)
{
Console.Write("請輸入一個整數:");
string str = Console.ReadLine();
int n = int.Parse(str);
for (int i = 1; i <= 10; i++)
{
int m = n * i;
Console.WriteLine("相乘後的數爲:" + m + "\t");
}
Console.ReadLine();
}
}
}
輸出結果:
經驗總結:
Console.WriteLine("相乘後的數爲:" + m + "\t");與 Console.WriteLine("相乘後的數爲:{0}",m);的區別