1. 台北市上班搭捷運、坐公車、和自己開車遲到的機率

直接看範例怎麼算就好了@@

using System.Security.Permissions;

namespace Q1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }

        decimal x, y, z, a, b, c;
        bool check()
        {
            x = decimal.Parse(textBox1.Text);
            y = decimal.Parse(textBox2.Text);
            z = decimal.Parse(textBox3.Text);
            a = decimal.Parse(textBox4.Text);
            b = decimal.Parse(textBox5.Text);
            c = decimal.Parse(textBox6.Text);

            foreach (var item in new[] {
                x,
                y,
                z,
                a,
                b,
                c
            }

            )
            {
                if (item < 0 || item > 1)
                {
                    ans.Text = "無解";
                    return false;
                }
            }
            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!check()) return;
            ans.Text = "在台北市上班遲到的機率為: " + (x * a + y * b + z * c);
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (!check()) return;
            ans.Text = "如果已知一個人上班遲到,那他是自己開車的機率為何: "
                +  (c*z/ (x * a + y * b + z * c)).ToString("f15");
        }
    }
}

Last updated