编写斐波那契(Fibonacci)数列的程序。用的是Microsoft Visual Studio 2010环境。望高手详细回答。谢谢!

[复制链接]
查看11 | 回复1 | 2011-4-6 07:29:04 | 显示全部楼层 |阅读模式
回复

使用道具 举报

千问 | 2011-4-6 07:29:04 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fibonacci
{

class Program

{

static void Main(string[] args)

{

Console.Write(\"请输入斐波那契数列的第n项:\");

int number = Convert.ToInt32(Console.ReadLine());

int sum=fib(number);

Console.WriteLine(sum);

}


private static int fib(int number)

{

if (number = 1)

{

return number;

}

else

{

return fib(number - 1) fib(number - 2);

}

}


}
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行