这是递归调用吗?

xyylmn 2008-03-23 12:31:44
有一列数的规则如下: 1、1、2、3、5、8、13、21、34......
0求第30位数是多少, 用递归算法实现。(C#语言)

下面是我写的代码,但我不知道这是不是属于递归调用,因为我对递归调用的概念很模糊了,请大家帮我看看!!!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 递归算法
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\0有一列数的规则如下: 1、1、2、3、5、8、13、21、34......");
Console.WriteLine();
Console.WriteLine("\0求第30位数是多少, 用递归算法实现。(C#语言)");
Console.WriteLine();
int[] intArray;
int number;
intArray = new int[30];
intArray[0] = 1;
intArray[1] = 1;
Console.WriteLine ("计算后得到数列如下:");
for (number = 2; number <=29; number++)
{
for (int count = 0; count<=number -2; count++)
{
for (int count1 = 1; count1<=number -1 ; count1++)
{
try
{
intArray[number] = intArray[count] + intArray[count1];
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine("数组越界");
}
}
}
}
for (number = 0; number <= 29; number ++)
{
Console.Write("{0}\0", intArray[number ]);
}
Console.WriteLine();
Console.WriteLine();

Console.WriteLine("这串数列第20位数是:{0}", intArray[29]);
Console.ReadLine();
}
}
}
...全文
74 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyylmn 2008-04-20
  • 打赏
  • 举报
回复
谢谢各位了
dancingbit 2008-03-23
  • 打赏
  • 举报
回复
递归调用一个明显的特征是有对自己的调用。
herowzz 2008-03-23
  • 打赏
  • 举报
回复
递归是重复调用自身的函数
changjiangboy 2008-03-23
  • 打赏
  • 举报
回复
斐波那契数列,以前用C写过(递归)..

我刚用C#写的

using System;
using System.Collections.Generic;
using System.Text;

namespace Fib
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\0有一列数的规则如下: 1、1、2、3、5、8、13、21、34......");
Console.WriteLine();
Console.WriteLine("\0求第30位数是多少, 用递归算法实现。(C#语言)");
Console.WriteLine();
int N = 30;
Console.WriteLine("\0这串数列第30位数是:" + fib(N));
Console.ReadLine();
}



// 返回数列的第n项值
static int fib(int n)
{
int result;

if (n == 0) //第0项,fib(0)设为0 {
return result = 0;
}

if (n == 1) //第1项
{
return result = 1;
}

return result = fib(n - 2) + fib(n - 1); //递归调用函数fib();
}
}
}
ivorstar 2008-03-23
  • 打赏
  • 举报
回复
这个不叫递归,递归的话大概是这种结构
Main(string[] args)
{
Console.WriteLine(fibo(20));
}

int fibo(int i)
{
if(i == 1)
return 1;
else if(i == 2);
return 1;
else
return fibo(i - 1) + fibo(i - 2);
}

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧