1   protected void Button1_Click(object sender, EventArgs e)
 2     {
 3         ListBox1.Items.Clear();//清空ListBox控件
 4         int p = 0, n = 0, a = 1, b = 1;//定义变量
 5         try
 6         {
 7             p = Convert.ToInt32(TextBox1.Text);//将字符型转换成数值型
 8         }
 9         catch//出现错误
10         {
11             Response.Write("<script>alert('请输入数值型数据');</script>");
12             TextBox1.Text = "15";
13             return;
14         }
15         for (n = 1; n <= p; n++)//对输入的数值进行遍历
16         {
17             ListBox1.Items.Add(a.ToString());//输出数值
18             ListBox1.Items.Add(b.ToString());//输出数值
19             a = a + b;//获取前两个数的和
20             b = a + b;//获取前两个数的和
21         }
22     }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2021-07-01
  • 2022-12-23
  • 2021-08-12
  • 2021-09-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2022-01-28
  • 2021-10-06
  • 2021-06-10
相关资源
相似解决方案