Numan GOCERI\’s Home Page

Hello World:)

Fibonacci Numbers

13.06.2008

Hello,
Today i’d to write a code which should display the fibonacci numbers in C Sharp Programming Language.
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”);
}

June 19, 2008 - Posted by | c sharp code, fibonacci numbers

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: