• 费式数列的几种解法



    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. }
  • 相关阅读:
    ethcoax_net 模型学习笔记(翻译自OPNET help)
    第一堂课学习
    (2)Dojo学习之模块化
    金融业的电子商务之路
    浅谈PE(私募股权)业务及系统建设:01. 业务介绍
    Don’t Be Afraid to Break Things
    基于Asp.net MVC的系统架构
    思考项目成功的关键因素
    金融业务系统中的数据库事务:01. 五类问题
    金融业务系统中的数据库事务:02. 解决问题
  • 原文地址:https://www.cnblogs.com/flay/p/2515461.html
Copyright © 2020-2023  润新知