打開visual studio.net,建立C#項目,選擇windows窗體程序,
在界面上放置文本框、標籤、按鈕控件,如下圖所示。
中間“=”按鈕的事件爲:
private void button1_Click(object sender, EventArgs e)
{
int n;
n = Convert.ToInt32(textBox1.Text);//得到文本框中數據
int i,f=1;
for(i=2;i<=n;i++)
{
f *= i;//計算階乘
}
textBox2.Text = f.ToString();//把結果寫入第二個文本框
}
是不是很簡單呢 ?