VF程序設(shè)計經(jīng)典例題1_第1頁
VF程序設(shè)計經(jīng)典例題1_第2頁
VF程序設(shè)計經(jīng)典例題1_第3頁
VF程序設(shè)計經(jīng)典例題1_第4頁
VF程序設(shè)計經(jīng)典例題1_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、1. 求園的面積(要求判斷半徑是否合理)CleaInpu r= to rIf r>0 S=3.14*r*r ?sElse ?半徑錯誤!Endif2. 求分段函數(shù)Y的值Y=2x5 x>0x x=0| x | x<0CleaInpu x= to xIf x>0 Y=2*x+5Else If x=0Y=x ElseY=abs(x) EndifEndif?y3. 輸入一個百分制成績判斷其等級(優(yōu)/良/中/及格/不及格)CleaInpu cj= to cjDo case Case cj>=90?優(yōu) Case cj>=80?良 Case cj>=70?中 Case

2、 cj>=60?及格 Orth?不及格Endcase4. 輸入若干個(個數(shù)不定)百分制成績判斷其等級(優(yōu)/良/中/及格/不及格)CleaInpu 請輸入處理幾個人的成績: to nFor i=1 to nInpu cj= to cjDo case Case cj>=90?優(yōu) Case cj>=80?良 Case cj>=70?中 Case cj>=60?及格 Orth?不及格Endcaseendfor5. 求S1+2+3. . . . . .+100CleaS=0For i=1 to 100 S=s+iEndfor?s 6. 求S1×2×3.

3、. . . . .×100Cleap=1For i=1 to 100 p=p*iEndfor?p7. 求S1+3+5. . . . .+99CleaS=0For i=1 to 99 step 2 S=s+iEndfor?s8. 求S12+34. . . . . .100CleaS=0For i=1 to 100 S=s+(-1)(i+1)*iEndfor?s9. 求S1+1/2+2/3+3/5. . . . . .前10項之和CleaS=0A=1B=1For i=1 to 10 S=s+a/b T=a A=b B=t+bEndfor?s10. 求S1!+2!+3!. . . . .

4、.+10!CleaS=0P=1For i=1 to 10P=p*i S=s+p Endfor?s11. 對學(xué)生表中所有入學(xué)成績650分的學(xué)生免去貸款CleaUse 學(xué)生Scan for入學(xué)成績>=650 .and. 貸款否=.t. Repl貸款否 with .f.EndscanUse* * * * * * * * * * * * * * * * * * * * *12. 輸出圖形CleaFor i=1 to 4 For j=1 to i?* Endfor ?EndforCleaFor i=1 to 4 For j=1 to 4-i? &&有一個空格 Endfor For

5、j=1 to 2*i-1?* Endfor ?EndforCleaFor i=1 to 4 For j=1 to 4-i? &&有一個空格 Endfor For j=1 to i?* Endfor ?Endfor13. 判斷一個整數(shù)是否素數(shù)CleaInpu x= to xFor i=2 to x-1 If mod(x,i)<>0Loop ElseExitEndifEndforIf i>x-1 ?x,是素數(shù)Else ?x,不是素數(shù)Endif14. 判斷十個整數(shù)是否素數(shù)CleaFor j=1 to 10Inpu x= to xFor i=2 to x-1 If m

6、od(x,i)<>0Loop ElseExitEndifEndforIf i>x-1 ?x,是素數(shù)Else ?x,不是素數(shù)EndifEndfor15. 找出兩個數(shù)的大數(shù)和小數(shù)CleaInpu x= to xInpu y to yIf x>y ?x,大,y,小Else ?y,大,x,小Endif16. 找出三個數(shù)的最大數(shù)和最小數(shù)CleaInpu x= to xInpu y to yInpu z to zIf x<y t=xx=yy=tElse If x<z t=xx=zz=t endifendifif y<z t=yy=zz=tendif?x,是最大數(shù),

7、z,是最小數(shù)17. 找出十個數(shù)的最大數(shù)和最小數(shù)CleaDime a(10)For i=1 to 10 Inpu to a(i)EndforMax=a(1)Min=a(1)For i=2 to 10 If max<a(i)Max=a(i) ElseIf min>a(i) Min=a(i)Endif EndifEndfor?max,min18. 找出2×3矩陣中的最大數(shù)和最小數(shù)cleadime a(2,3)for i=1 to 2 for j=1 to 3input a(+str(I,2)+,+str(j,2)+)= to a(I,j) endforendformax=a(1

8、,1)min=a(1,1)for i=1 to 2 for j=1 to 3if max<a(I,j) max= a(I,j)else if min> a(I,j) min= a(I,j) endifendif endforendfor?max=,max,min=,min19. 對三個整數(shù)從大到小排序ClearInput a= to aInput b= to bInput c= to cIf a<b T=a A=b B=tElse If a<c t=a A=cc=t endifendifIf b<c T=b A=c c=tendif?a,b,c20. 對十個整數(shù)從

9、大到小排序(用選擇法和起泡法兩種方法)選擇法:ClearDime a(10)For i=1 to 10 Input to a(i)EndforFor i=1 to 9 Max=a(i) Num=i For j=i+1 to 10If max<a(j) max=a(j) Num=jEndif Endfor If i<>num t=A(i) a(i)=a(num) a(num)=t EndifEndforFor i=1 to 10 ?a(i),' 'Endfor起泡法:ClearDime a(10)For i=1 to 10 Input to a(i)Endfor

10、For i=1 to 9 For j=1 to 10-i If a(j)<a(j+1) t=A(j) a(j)=a(j+1) a(j+1)=t Endif endforEndforFor i=1 to 10 ?a(i),' 'Endfor21. 輸出Fibonacci(斐波那契)數(shù)列的前十項ClearDime a(10)a(1)=1a(2)=1For i=3 to 10 a(i)=a(i-1)+a(i-2)EndforFor i=1 to 10 ?A(i)Endfor22. 輸出楊輝三角的前十行ClearDime a(10,10)For i=1 to 10 A(I,1)=

11、1 A(I,i)=1EndforFor i=3 to 10 For j=2 to i-1A(I,j)=a(i-1,j)+a(i-1,j-1) EndforEndforFor i=1 to 10 For j=1 to i?A(I,j) Endfor ?Endfor23. 對2×3矩陣轉(zhuǎn)置CleaDime a(2,3),b(3,2)for i=1 to 2 for j=1 to 3input to a(I,j) endforendforfor i=1 to 3 for j=1 to 2b(I,j)=a(j,i) endforendforfor i=1 to 3 for j=1 to 2?

12、b(I,j) Endfor ?endfor24. 求三位數(shù)中的所有水仙花數(shù)(即指一個三位數(shù),其各位數(shù)字立方和等于該數(shù)本身)Cleafor x=100 to 999 a=int(x/100) b= mod(int(x/10),10) c=mod(x,10) if x=a*a*a+b*b*b+c*c*c ?xEndifendfor25. 求100以內(nèi)的所有完數(shù)(即一個數(shù)恰好等于除它本身外的所有因子之和)Cleafor i=3 to 100 s=0 for j=1 to i-1 if mod(i,j)=0 s=s+j endif endfor if i=s ?i endifendfor 26. 已知

13、三角形的三邊(從鍵盤輸入),求其面積(S2=p(p-a)(p-b)(p-c), p=(a+b+c)/2)Clearinput 'a=' to ainput 'b=' to binput 'c=' to cif a+b>c and a+c>b and b+c>a p=(a+b+c)/2 s=sqrt(p*(p-a)*(p-b)*(p-c) ?selse ?'三邊不能組成三角形'Endif27. 求二元方程的根(分三種情況:兩個不等實根,兩個相等實根,無實根)cleainpu 'a=' to a &a

14、mp;&a<>0inpu 'b=' to b &&b<>0inpu 'c=' to ci=b*b-4*a*c if i<0 ?"方程無實根!" else if i=0 r=(-b)/(2*a) ?"方程有兩個相等實數(shù)根:",r else x1=(-b+sqrt(i)/(2*a) x2=(-b-sqrt(i)/(2*a) ?"方程有兩個不相等實數(shù)根:",x1,x2 endifendif28. 輸入任意一個五位整數(shù),前后對應(yīng)位置上的數(shù)據(jù)進(jìn)行交換重新排列(

15、即逆序排列)(例:2598448952)cleadime a(5)inpu to ba(1)=int(b/10000)a(2)=mod(int(b/1000),10)a(3)=mod(int(b/100),10)a(4)=mod(int(b/10),10)a(5)=mod(b,10)for i=1 to int(5/2) t=a(i) a(i)=a(6-i) a(6-i)=tendforc=a(1)*10000+a(2)*1000+a(3)*100+a(4)*10+a(5)?b,c29. 找出一個3x3矩陣的“鞍點”,即該位置上的元素在該行上最大,在該列上最小(也有可能沒有鞍點)cleadim

16、e a(3,3) flag=.t.for i=1 to 3 for j=1 to 3 input 'a('+str(I,2)+','+str(j,2)+')=' to a(i,j) endforendfor for i=1 to 3 max=a(i,1) col=1 for j=2 to 3 if max<a(i,j) max=a(i,j) col=j endif endfor min=a(1,col) row=1 for k=2 to 3 if min>a(k,col) min=a(k,col) row=k endif endfor

17、 if max=min ?a(row,col),'是鞍點,在',row,'行',col,'列' flag=.f. endifendforif flag=.t. ?'無鞍點'endif30. 求S(n)=a+aa+aaa+.+aaa.aaa(其中有n個a)之值,a是一個數(shù)字,n和a由鍵盤鍵入(例如:2+22+222+22222+22222,此時n=5)cleainpu 'a=' to ainpu 'n=' to ns=0t=afor i=1 to n s=s+t t=a+t*10endfor?s31.

18、把一張一元鈔票,換成一分、二分和五分硬幣,每種至少11枚,問有多少種方案?   13cleas=0for a=11 to 100  for b=11 to 50    for c=11 to 20      if a+2*b+5*c=100        s=s+1      endif    endfor  endfornext?s32.一只猴子一天從山上摘來一袋桃子,從這天開始,它每天都要把袋中的桃子平分為二堆,吃掉其中的一堆,然后再從剩下的桃中拿出一個解讒,等到第10天,它發(fā)現(xiàn)袋中只有一只桃可吃啦,問猴子總共摘了多少桃。   1534cleadime f(10)f(1)=1f(2)=4f(3)=10s=0for n=4 to 10f(n)=

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論