求一个数列:1/1,2/1,3/2,5/3,8/5,13/8,21/13…求出这个数列的前20项之和。
求一个数列:1/1,2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day011
{
class MyClass
{
}
class Program
{
static void Main(string[] args)
{
#region 求一个数列:1/1,2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
int a = 1, b = 1,c;
double sum = 0;
for (int i = 0; i < 20; i++)
{
sum = (double)a / b;
c = b;
b = a;
a = b + c;
}
Console.WriteLine("求一个数列:1/1,2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。");
Console.WriteLine(sum);
Console.ReadKey();
#endregion
}
}
}
导入
如果你想加载一篇你写过的.md文件,在上方工具栏可以选择导入功能进行对应扩展名的文件导入,
继续你的创作。