Рекурсия

 avatar
unknown
plain_text
2 years ago
1.3 kB
4
Indexable
namespace Factoriel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private int factoriel(int n)
        {
            if (n == 1) return 1;
            else
                return n * factoriel(n - 1);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int a = factoriel(int.Parse(textBox1.Text));
            label1.Text = a.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.Application.Exit();
        }
        private int suma(int n)
        {
            if (n == 1) return 1;
            return n + suma(n - 1);
        }
    private void button3_Click(object sender, EventArgs e)
        {
            int a = suma(int.Parse(textBox1.Text));
            label1.Text = a.ToString();
        }
        private int fibonacci(int n)
        {
            if (n <= 2) return 1;
            else
                return fibonacci(n - 1) + fibonacci(n - 2);
        }
        private void button4_Click(object sender, EventArgs e)
        {
            int a = fibonacci(int.Parse(textBox1.Text));
            label1.Text = a.ToString();
        }
    }
}
Editor is loading...