设计界面:一个Label标签
编写代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 斐波那契数列
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int[] a = new int[10];
a[0] = 0;
a[1] = 1;
label1.Text = "斐波那契数列:0 1";
for (int i = 2; i <a.Length;i++ )
{
a[i] = a[i - 2] + a[i - 1];
label1.Text += "\n 索引"+i +" 值: " +a[i];
}
}
}
}
运行结果: