111,120
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
double Total = 0;
for (int i = 0; i < 20; i++)
{
double NR = GetN(2 + i);
double MR = GetN(1 + i);
double R = NR / MR;
Total += R;
Console.WriteLine(NR.ToString() + "/" + MR.ToString()
+ "=" + R.ToString());
}
Console.WriteLine(Total.ToString());
Console.Read();
}
static double GetN(int N)
{
if (N == 0 || N == 1)
return 1;
return GetN(N - 2) + GetN(N - 1);
}
}
}
static void Main(string[] args)
{
int length = 20;
double a, b, c;//分子
int A, B, C;//分母
a = 2; b = 3;
A = 1; B = 2;
double sum = a / A + b / B;
c = a + b;
C = A + B;
for (int i = 2; i < length; i++)
{
Console.WriteLine(c + "/" + C);
sum += c / C;
a = b;
b = c;
c = a + b;
A = B;
B = C;
C = A + B;
}
Console.WriteLine("=" + sum);
Console.Read();
}