斐波拉契数列
- 斐波拉契数列,求第n个值是多少
有这样一个数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,求出第n 位的值
int num1 = 1, num2 = 1, sum = 0;
console.WriteLine("请输入一个数:");
int int_Num = Convert.ToInt32(Console.ReadLine());
for (int i = 3; i <= int_Num; i++)
{
sum = num1 + num2;
num1 = num2;
num2 = sum;
}
Console.WriteLine(sum);
- 写一个日期的窗体程序
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1990; i < 2050; i++)
{
this.comboBox1.Items.Add(i);
}
}
private void comboBox2_selectedindexchanged(object sender, EventArgs e)
{
this.comboBox3.Items.Clear();
int year = Convert.ToInt32(this.comboBox1.Text);
int months = Convert.ToInt32(this.comboBox2.Text);
int day = 31;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
switch (months)
{
case 4:case 6:case 9:case 11:
day = 30;
break;
case 2:
day = 29;
break;
default:
break;
}
}
else
{
switch (months)
{
case 4:case 6:case 9:case 11:
day = 30;
break;
case 2:
day = 28;
break;
}
}
for (int i = 1; i <= day; i++)
{
this.comboBox3.Items.Add(i);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.comboBox2.Text = null;
this.comboBox3.Text = null;
this.comboBox2.Items.Clear();
this.comboBox3.Items.Clear();
for (int i = 1; i < 13; i++)
{
this.comboBox2.Items.Add(i);
}
}
文章最后发布于: 2018-08-30 23:45:46
相关阅读
Response.setContentType(MIME)的作用及参数列表
Response.setContentType(MIME)的作用是时客户端的浏览器区分不同种类的数据,并根据不同的MIME调用浏览器内不同的程序嵌入模块来
转载连接: https://www.cnblogs.com/lgx5/p/6271098.html 一、LIST概述 所属命名空间:System.Collections.Generic publ
/// <summary> /// 获取cpu温度 /// </summary> /// <returns></returns> internal static s
C# Directory.GetFiles()获取多个类型格式的文件
转自:http://www.cnblogs.com/songxingzhu/p/6000070.html第一种方式System.IO.Directory.GetFiles()获取多个类型格式的文件 Syst
【转】基于C#的WinForm中DataGridView控件操作汇总
基于C#的WinForm中DataGridView控件操作汇总 一、单元格内容的操作 *****// 取得当前单元格内容 Console.WriteLine(Data