|登录 |注册

楼主: goodday
打印 上一主题 下一主题

我的开发天空 [很惊人的 asp.net 教学] 十八页

 关闭 [复制链接]
goodday
2007-10-31 11:38 PM
番茄兄 Dhilip89  到你们 出题咯
Dhilip89
2007-10-31 11:40 PM
原帖由 goodday 于 2007-10-31 11:31 PM 发表
Dhilip89 你没讲我会继续用错


static int Fibonacci (int x)
{
   // Console.WriteLine ("x = {0}", x);
   if (x <= 1)
   {
      return 1;
   }
   return Fibonacci (x-1) + Fibonacci (x-2);
}
         
static void Main( )
{
   int loop = 5;
   for (int i = 0; i <= loop; i++)
        {
                   Console.WriteLine ("{0} ", Fibonacci (i));
        }
   Console.ReadKey();
}
Dhilip89
2007-10-31 11:44 PM
原帖由 goodday 于 2007-10-31 11:38 PM 发表
番茄兄 Dhilip89  到你们 出题咯


暂时还不知道要出什么
goodday
2007-10-31 11:49 PM
原帖由 Dhilip89 于 2007-10-31 11:40 PM 发表


static int Fibonacci (int x)
{
   // Console.WriteLine ("x = {0}", x);
   if (x  

goodday
2007-10-31 11:50 PM
跑咯~~~ 没bug~~~~
Super-Tomato
2007-10-31 11:53 PM
沒安裝C編譯器, 不過只是求fibonacci, 用其他語言也一樣

javascript:

  1. function fibonacci(a) {
  2.         return a==0?0:a==1?1:a==2?1:fibonacci(a-1)+fibonacci(a-2);
  3. }
  4. alert(fibonacci(10));  //得 55
复制代码
goodday
2007-10-31 11:56 PM
原帖由 Super-Tomato 于 2007-10-31 11:53 PM 发表
沒安裝C編譯器, 不過只是求fibonacci, 用其他語言也一樣

javascript:

function fibonacci(a) {
        return a==0?0:a==1?1:a==2?1:fibonacci(a-1)+fibonacci(a-2);
}
alert(fibonacci(10));  //得 55

哇~~~~~
你需不需要酱懒哦
一短过???
Super-Tomato
2007-11-1 12:01 AM
我只求精於簡, fibonacci是我第一次接觸C的第一個小練習


C

  1. #include<stdio.h>

  2. int fibonacci(int a);

  3. void main()
  4. {
  5.         int n;
  6.       
  7.         printf("Fibonacci(x) : ");
  8.         scanf("%d", &n);
  9.         printf("%d\n", fibonacci(n));
  10. }

  11. int fibonacci(int a)
  12. {
  13.         return a==0?0:a==1?1:a==2?1:fibonacci(a-1)+fibonacci(a-2);
  14. }
复制代码

[ 本帖最后由 Super-Tomato 于 2007-11-1 12:13 AM 编辑 ]
goodday
2007-11-1 12:11 AM
跑咯 要开工咯
忙~~~~~~~
Dhilip89
2007-11-1 12:24 AM
fibonacci.cpp

  1. #include <iostream>
  2. using namespace std;

  3. int f(int n);

  4. int main()
  5. {
  6.         int n, i;

  7.         cout << "Input: ";
  8.         cin >> n;
  9.         cout << "Fibonacci sequences: " << n << endl;

  10.         for (i = 0; i <= n; i++)
  11.         {
  12.                 cout << f(i);
  13.                 if (i <= n - 1) cout << ", ";
  14.         }
  15.         cout << endl;
  16.        
  17. }

  18. int f(int n)
  19. {
  20.         if (n <= 1) return(n);
  21.         return(f(n - 1) + f(n - 2));
  22. }
复制代码
您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2025-5-16 06:43 AM , Processed in 0.090453 second(s), 20 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部