Рекурсия
unknown
plain_text
3 years ago
1.4 kB
10
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 = int.Parse(textBox1.Text);
for(int i=1; i<=a; i++)
{
label1.Text += fibonacci(i).ToString() + ", ";
}
}
}
}Editor is loading...