zoukankan      html  css  js  c++  java
  • 费式数列的几种解法


    program Project1; {$APPTYPE CONSOLE} uses SysUtils; //-------------for 语句实现---------------------------- const N = 8; var Fib: array[0..8] of Integer ; i:Integer; begin Fib[0] := 0; Fib[1] := 1; for i:=2 to N do Fib[i] :=Fib[i -1] + Fib[i -2]; for i := 0 to N do Writeln(Fib[i]); Readln; { TODO -oUser -cConsole Main : Insert code here } end. { //---------------------While....do语句实现 --------------------------------------------- const N = 8; var Fib: array[0..N] of Integer; i:Integer; begin Fib[0] :=0; Fib[1] :=1; i :=2; while i<=N do begin Fib[i] :=Fib[i -1] + Fib[i - 2]; Inc(i); end; //-------------------------------------------------------------- i:=0; while i <=8 do begin Writeln(Fib[i]); Inc(i); end; Readln; end. } //====<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //====<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< { //----------------Repeat..until 语句实现---------------------------------------------------- const N = 8; var Fib: array[0..N] of Integer; i:Integer; begin Fib[0] :=0; Fib[1] :=1; i:=2; repeat Fib[i] :=Fib[i -1]+Fib[i -2]; Inc(i); until i >=N ; i:=0; repeat Writeln(Fib[i]); Inc(i); until i >=N; Readln; end. } //====<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //====<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< { //----------------goto 语句实现---------------------------------------------------- const N = 8; var Fib: array[0..N] of Integer; i:Integer; label Sum, Applear, ends; begin Fib[0] :=0; Fib[1] :=1; i:=2; //--------------------------------- sum: Fib[i]:=Fib[i -1] + Fib[i -2]; inc(i); if i <= N then goto sum; //---------------------------------- i:=0; Applear: Writeln(Fib[i]); Inc(i); if i <=N then begin goto Applear; end else begin goto ends; end; ends: Readln; end. }
  • 相关阅读:
    date format记录
    python同时遍历两个list
    Windbg分析DMP文件
    DNS原理及其解析过程(转)
    有关正则表达式的详细内容
    sizeof _countof _tcslen的比较
    关于androidX
    UML类图
    springBoot 访问html页面遇到的坑
    hashmap 的实现原理
  • 原文地址:https://www.cnblogs.com/flay/p/2515461.html
Copyright © 2011-2022 走看看