Rakursiq
unknown
csharp
2 years ago
1.3 kB
2
Indexable
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private int fib(int n) { if (n <= 2) return 1; return fib(n - 1) + fib(n - 2); } private void button3_Click(object sender, EventArgs e) { textBox2.Text = ""; int a = int.Parse(textBox1.Text); for (int i = 1; i <= a; i++) { textBox2.Text += fib(i).ToString() + ","; } } private int suma(int n) { if (n == 1) return 1; return n + suma(n - 1); } private void button2_Click(object sender, EventArgs e) { textBox2.Text = ""; int a = suma(int.Parse(textBox1.Text)); textBox2.Text = a.ToString(); } private int factoriel(int n) { if (n == 1) return 1; else return n * factoriel(n - 1); } private void button1_Click(object sender, EventArgs e) { { textBox2.Text = ""; int a = factoriel(int.Parse(textBox1.Text)); textBox2.Text = a.ToString(); } } }
Editor is loading...