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. }
  • 相关阅读:
    prometheus client_golang使用
    etcd相关知识
    基于kubernetes v1.17部署dashboard:v2.0-beta8
    浅谈 Linux namespace
    使用kubeadm部署K8S v1.17.0集群
    和我一步步部署 kubernetes 集群
    go语言开发(二)---变量
    Golang学习笔记(一)-Go语言环境安装以及运行代码
    pycharm中设置pylint工具
    keeplive使用
  • 原文地址:https://www.cnblogs.com/flay/p/2515461.html
Copyright © 2011-2022 走看看