求一个长度为100个数的斐波那契数列,然后分别第99个数和第98个数的比例,
以及将该数列中位置数能被10整除的数(即排第10位,第20位,第30位....的数),
分别与数组b[10]={2,0,3,0,4,0,5,0,6,0}的10个数依次相除,求最后得到的结果。
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace t2_2
{
class Program
{
static void Main(string[] args)
{
double a;
long[] fac;
int[] b = { 2, 0, 3, 0, 4, 0, 5, 0, 6, 0 };
fac = new long[50];
fac[0] = 1;
fac[1] = 1;
for (int i = 2; i < 50; i++)
fac[i] = fac[i - 1] + fac[i - 2];
for (int i = 0; i < 50; i++)
Console.WriteLine("fac[" + i + "]=" + fac[i]);
Console.Read();
a = fac[49] * 1.0 / fac[48];
Console.WriteLine(a);
try
{
for (int i = 1; i <= 10; i++)
{
a = fac[i * 5] * 1.0 / b[i];
Console.WriteLine(fac[i * 5] + "/" + b[i] + "=" + a);
}
}
catch
{
Console.WriteLine("发生异常");
Console.Read();
}
Console.Read();
}
}
}