close

題目:
請設計一個程式,計算下面數列的和。
例如:1+1/2+1/4+1/8+....+1/128=?

        Label1.Text = "";
        double ans = 0;
        // 計算 1+(1/2)+(1/4)+...+(1/128) = ?
        for (int i = 0; i < 8; i++)
        {
            ans += (1 / Math.Pow(2, i));
        }
        Label1.Text = string.Format("The answer is {0}", ans.ToString());
        //Math.Pow 說明 https://msdn.microsoft.com/zh-tw/library/system.math.pow(v=vs.110).aspx


arrow
arrow
    全站熱搜

    Roger 發表在 痞客邦 留言(0) 人氣()