《编译文档中示例源程序.docx》由会员分享,可在线阅读,更多相关《编译文档中示例源程序.docx(4页珍藏版)》请在第壹文秘上搜索。
1、mainadd100;functionadd(x:Integer):float;varresult:Integer.beginifx=lthenreturnX;result:=x+add(x-l);returnresult;end;beginjpl.printint(add(100);end.mainE;varnums:Integer;es:Float;/ArrayofFloat.i:Integer;functionfactorial(Times:Integer):float;varResultiFloat;beginResult:=1.0;while(Times0)dobeginResult
2、i=Result*Times;Timesi=Times-I;end;return1/Result;end;functione(1.evel:Integer):float;varResult:Float;beginResult:=1.0;while(1.evel0)dobeginResult:=Result+factorial(1.evel);1.evel:=1.evel-1;end;returnResult;end;beginnums:=2;while(factorial(nums)=0.00000001)dobeginnums:=nums+l;end;IwantourEexcatlyenou
3、gh,soitrytofindafactiriallessthanthat.Thisnotverysmart,butmayletyouseemoreJP1.O.)nums:=nums-l;newarrayes:=Floatnums;es0:=2.O;esl:=2.5;i:=2;fori:=2to(nums-l)dobeginesi:=e(i+l);end;fori:=0tonms-ldobeginjpl.printfloat(esi);end;end.mainfibinacci_float;vari:Integer;list:float;functionfunc(i:Integer):floa
4、t;beginif(i=O)thenreturn1.O;if(i=1)thenreturn1.O;return(func(i-l)+func(i-2);end;beginnewarraylist:=float20;fori:=0to19dobeginlisti:=func(i);end;1 :=0;fori:=0to19dobeginJP1.O.PRINTF1.OAT(listi);end;end.mainpl02;var1: Integer;list:Integer;functionfunc(i:Integer):Integer;beginif(i=0)thenreturn1;if(i=1)
5、thenreturn1;return(func(i-l)+func(i-2);end;begini:=O;newarrayIiSt:二InIeger20;while(i20)dobegin/JP1.O.Printint(func(i);listi:=func(i);i:=i+1;end;i:=0;while(i=1000)thenthislineisOK,buti/wanttoshowyouBoolean.)if(IsPrlmE)thenJP1.O.printint(i);end;end.mainTypes;procedureShowType(XiInteger);beginJP1.O.PRINTSTRINGCltisanInteger./z);end;procedureShowType(XrFloat);beginJP1.O.PRlNTSTRINGritisaflaot.*);end;beginShowType(I);ShowType(2.1);end.mainwrongfunctionwrongx():integer;beginx=x+1;returnx+x;endbeginwrongx(3);end;