計(jì)算機(jī)二級(jí)VF程序設(shè)計(jì)的實(shí)例

字號(hào):

(一) 隨機(jī)出10道100以內(nèi)的整數(shù)加減法算數(shù)題
    clear
    ts=1
    do whie ts<=10
    czf=iif(rand()>0.5,"+","-")
    num1=rand()*100
    num2=rand()*100
      if =czf="+"
      if num1+num2>100
        loop
      else
        if num1<num2
          loop
        endif
      endif
    ?"("+str (ts,2)+")"+” “+str (num1,2)+czf+str(num2,2)+"=”
    ts=ts+1
    enddo
     (二) 計(jì)算1,1/2,1/3...1/n之和,當(dāng)<0.001時(shí)停止
    set decimal +0 2
    n=1
    nsum=0
    do while .t.
    if 1/n <0.001
      exit
    endif
    nsum=nsum+2
    n=n+1
    enddo
    wait windows "該系統(tǒng)之和為"+
    (三) 計(jì)算生肖自定義函數(shù)sx()
    function sx
    arameters nyear
    local n,csx
    csx="羊猴雞狗豬鼠?;⑼谬埳唏R"
    if parameters()=0
    nyear =year(date())
    endif
    n=mod(nyear,12)         return substr (ncsx,2+"N"+1,2)
    endfunc
    (四) 計(jì)算 S=1!+2!+3!+4!+5!+6!+7!+8!+9!
    s=0
    for i=1 to 9
      s=s+fjc(i)
    endfor
    ?s
    function fjc
    parameters x
    p=1
    for n=1 to x
      p=p*x
    endfor
    return p
    endfunc