- 分享
- 0
- 人气
- 0
- 主题
- 3
- 帖子
- 198
- UID
- 19026
- 积分
- 2953
- 阅读权限
- 20
- 注册时间
- 2005-10-14
- 最后登录
- 2018-9-19
- 在线时间
- 1609 小时
|
做了一些修正:
fibonacci.cpp
- #include <iostream>
- using namespace std;
- int f(int n);
- int main()
- {
- int n, i;
- cout << "[Fibonacci Calculator (C++ Version)] - By Dhilip89" << endl;
- cout << "Computations: ";
- cin >> n;
- cout << "Fibonacci sequences: " << endl;
- for (i = 0; i <= n; i++)
- {
- cout << f(i);
- if (i <= n - 1) cout << ", ";
- }
- cout << endl;
-
- }
- int f(int n)
- {
- if (n <= 1) return(n);
- return(f(n - 1) + f(n - 2));
- }
复制代码
fibonacci.c
- #include <stdio.h>
- int f(int n);
- main()
- {
- int n, i;
-
- printf("[Fibonacci Calculator (C Version)] - By Dhilip89\n");
- printf("Computations: ");
- scanf("%d", &n);
- printf("Fibonacci sequences:\n");
- for (i = 0; i <= n; i++)
- {
- printf("%d", f(i));
- if (i <= n - 1) printf(", ");
- }
- printf("\n");
- }
- int f(int n)
- {
- if (n <= 1) return(n);
- return(f(n - 1) + f(n - 2));
- }
复制代码
fibonacci.cs (Untested experimental code)
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static int F(int n)
- {
- if (n <= 1) { return n; }
- return F(n - 1) + F(n - 2);
- }
- static void Main()
- {
- int n, i;
-
- Console.WriteLine("[Fibonacci Calculator (C# Version)] - By Dhilip89");
- Console.Write("Computations: ");
- n = Console.ReadLine();
- Console.WriteLine("Fibonacci sequences:");
- for (int i = 0; i <= n; i++)
- {
- Console.Write("{0}", F(i));
- if (i <= n - 1) { Console.Write(", "); }
- }
- Console.WriteLine("");
- }
- }
- }
-
复制代码
fibonacci.au3
- Func _Fibonacci($n)
- If $n <= 1 Then Return $n
- Return _Fibonacci($n - 1) + _Fibonacci($n - 2)
- EndFunc
- $n = InputBox("[Fibonacci Calculator (AutoIt Version)] - By Dhilip89", "Computations:", "", "", 350, 20)
- Local $str
- For $i = 0 To $n Step 1
- $str &= _Fibonacci($i)
- If $i <= $n - 1 Then $str &= ", "
- Next
- MsgBox(0, "Fibonacci sequences", $str)
复制代码
[ 本帖最后由 Dhilip89 于 2007-11-1 08:00 PM 编辑 ] |
|