C#——Windows程序用递归方法计算指定数字的阶乘

首先设计如下界面

C#——Windows程序用递归方法计算指定数字的阶乘

编写如下代码:

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            int jc =Convert .ToInt16 ( textBox1.Text);
            label1.Text ="数字"+Convert .ToString (jc)+"的阶乘结果为"+Convert .ToString( Result(jc));
        }

        public int Result(int jc) {
            int result=0;
            if (jc == 1)
            {
                return 1;
            }
            else {
                result = jc*Result(jc - 1);
                return result;
            }
        }

    }

运行结果:

C#——Windows程序用递归方法计算指定数字的阶乘