C#練習,應用for,while,do-while迴圈

戒生發表於2018-10-17

for迴圈

  for (int i = 1; i <= 5; i++)
        {
            Console.WriteLine(Math.Pow(i, 2));//Math.Pow(i, 2)-->輸出i的2次方
        }

while迴圈

 int j = 1;
    while (j <= 5)
    {
        Console.WriteLine(Math.Pow(j, 2));
        j++;
    }

do-while迴圈

  int k = 1;
    do
    {
        Console.WriteLine(Math.Pow(k, 2));
        k++;
    } while (k <= 5);

相關文章