Fibonacci Numbers
Hello,
Today i'd to write a code which should display the fibonacci numbers.
As i remember, the code that i've written is wrong:(.
So, now i rewrite the code in a few minutes. As a computer engineering student, this is so easy to solve but if u're not worried :s.
Anyway,
kodumuz şu şekilde(here is the code):
/*info*/
//textBox1 holds the number which calculates the fibonacci series "up to".
//textBox2 shows the result according to the value of textBox1.Text.
//the array "sayi" holds the numbers in the fibonacci serie.
private void button1_Click(object sender, EventArgs e)
{
int N = Convert.ToInt32(textBox1.Text);
int[] sayi = new int[N + 1];
sayi[0] = 1;
if (N > 0)
{
sayi[1] = 1;
if (N == 1)
textBox2.Text = sayi[N].ToString();
else
{
for (int i = 2; i <= N; i++)
sayi[i] = sayi[i - 1] + sayi[i - 2];
textBox2.Text = sayi[N].ToString();
}
}
else if(N == 0)
textBox2.Text = sayi[N].ToString();
else
MessageBox.Show("istenilen aralikta değil", "Hata");
}
Yorum yaz! :: Arkadaşına Gönder!
0 yorum yazilmistir « Önceki - Sonraki »