シミュレーション MEMO
● F-BASICプログラムの練習 1
1.級数の和
N=100:S=0 for I=1 to N:S=S+I:next print "N=";N;"....";S stop end |
N=50:S1=0:S2=0:S3=0 for I=1 to N:S1=S1+I:S2=S2+I^2:S3=S3+I^3:next print "n=";N print using "sum k=###### N(N+1)/2=######";S1,N*(N+1)/2 print using "sum k^2 ###### N(N+1)(2N+1)/6=######";S2,N*(N+1)*(2*N+1)/6 print using "sum k^3 ####### N^2(N+1)^2/4=#######";S3,N^2*(N+1)^2/4 stop:end |
input "RN=";rn:randomize rn for i=1 to 10:x=int(rnd(1)*6+1):print x;:next stop:end |
dim dx(4),dy(4) for i=1 to 4:read dx(i),dy(i):next input "RN=";rn:randomize rn:input "N=";n color 0,15:cls:x0=300:y0=200:x=0:y=0:l=5 circle(x0,y0),3,5 for i=1 to n ir=int(rnd(1)*4+1):x1=x+dx(ir):y1=y+dy(ir) line(x0+x*l,y0-y*l)-(x0+x1*l,y0-y1*l),,0 x=x1:y=y1 next circle(x0+x*l,y0-y*l),3,9 stop data 1,0, 0,1, -1,0, 0,-1 end |
![]() |
dim dx(4),dy(4) for i=1 to 4:read dx(i),dy(i):next input "RN=";rn:randomize rn:input "N=";n input "number of tries";m:color 0,15:cls:r2=0 for k=1 to m x=0:y=0 for i=1 to n ir=int(rnd(1)*4+1):x=x+dx(ir):y=y+dy(ir) next r2=r2+x^2+y^2 next print "N=";n;" M=";m;" R=";sqr(r2/m):stop data 1,0, 0,1, -1,0, 0,-1 end |