推扬网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
推扬网 门户 你问我答 查看内容

胡东海:C#题目,用递归算法算1.1.2.3.5.8.13....第30个是多少

2020-8-12 17:17| 发布者: admin| 查看: 53| 评论: 0

摘要: 聂宁的回答: private static int count=1; public int digui(int a,int b){ int c=a+b; count++; if(count

聂宁的回答:

private static int count=1; public int digui(int a,int b){ int c=a+b; count++; if(count <= 30){ digui(b,c); } return c; }

杨近川的回答:

private static int count=1; public int digui(int a,int b){ int c=a+b; count++; if(count <= 30){ digui(b,c); } return c; }

许伟的回答:

public static int Add(int i) { if(i<=0) { return 0; } else if(i>0 && i<=2) { return 1; } else { return Add(i-1)+Add(i-2); } }

王思远的回答:

f(x)=f(x-1)+f(x-2) 设f(0)=1 设f(1)=1 然后就好了 int f(x) { if(x==0||x==1)return 1; else return f(x-1)+f(x-2); } 没调试过^^

言艺的回答:

using System; using System.Collections.Generic; using System.Text; namespace Consoleapplication2 { class Program { static void Main(string[] args) { int[] num=new int[30]; num[0] = 1; num[1] = 1; System.Console.Write(num[0] + " " + num[1] + " "); for (int i = 0; i < 28; i++) { num[i + 2] = num[i+1] + num[i]; System.Console.Write(num[i+2]+" "); } System.Console.Read(); } } }


鲜花

握手

雷人

路过

鸡蛋

最新评论

热门推荐
最新资讯

广告服务|投稿要求|禁言标准|版权说明|免责声明|手机版|小黑屋|推扬网 ( 粤ICP备18134897号 )|网站地图 | 邮箱:vayae@hotmail.com

GMT+8, 2025-6-15 11:01 , Processed in 0.065479 second(s), 28 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

返回顶部