(第一天)求斐波那契数列第n个数
using System;
namespace 斐波那契
{
class Program
{
static void Main(string[] args)
{
UInt32 n;
Console.WriteLine("输入求结果的个数值:");
n = Convert.ToUInt32(Console.ReadLine());
if (n == 1)
{
Console.WriteLine("第一个数为1");//第一个数没有不符合以下算法
}
else
{
int i, a = 0, b = 1, result = 1;
for (i = 1; i < n; i++)//只有小于才能正确实现
{
result = a + b;
a = b;
b = result;
}
Console.WriteLine("第{0}个数为{1}", n, result);
}
Console.ReadKey();
}
}
}
namespace 斐波那契
{
class Program
{
static void Main(string[] args)
{
UInt32 n;
Console.WriteLine("输入求结果的个数值:");
n = Convert.ToUInt32(Console.ReadLine());
if (n == 1)
{
Console.WriteLine("第一个数为1");//第一个数没有不符合以下算法
}
else
{
int i, a = 0, b = 1, result = 1;
for (i = 1; i < n; i++)//只有小于才能正确实现
{
result = a + b;
a = b;
b = result;
}
Console.WriteLine("第{0}个数为{1}", n, result);
}
Console.ReadKey();
}
}
}