1、VF编程题库第六章 程序设计编程题1. 求园的面积(要求判断半径是否合理)CleaInpu r= to rIf r0 S=3.14*r*r ?sElse ?半径错误!Endif2. 求分段函数Y的值CleaInpu x= to xIf x0 Y=2*x+5Else If x=0Y=x ElseY=abs(x) EndifEndif?y3. 输入一个百分制成绩判断其等级(优/良/中/及格/不及格)CleaInpu cj= to cjDo case Case cj=90?优 Case cj=80?良 Case cj=70?中 Case cj=60?及格 Orth?不及格Endcase4. 输入若干
2、个(个数不定)百分制成绩判断其等级(优/良/中/及格/不及格)CleaInpu 请输入处理几个人的成绩: to nFor i=1 to nInpu cj= to cjDo case Case cj=90?优 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. 求S123. . . . . .100Cleap=1For i=1 to 100 p=p*iEndfor?p7. 求S1+3+5. . . .
3、 .+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!. . . . . .+10!CleaS=0P=1For i=1 to 10P=p*i S=s+p Endfor?s11. 对学生表中所有入学成绩650分的学生
4、免去贷款CleaUse 学生Scan for入学成绩=650 .and. 贷款否=.t. Repl贷款否 with .f.EndscanUse12. * * * * * * * * * * * * * * * * * * * * *输出图形CleaFor i=1 to 4 For j=1 to i?* Endfor ?EndforCleaFor i=1 to 4 For j=1 to 4-i? &有一个空格 Endfor For j=1 to 2*i-1?* Endfor ?EndforCleaFor i=1 to 4 For j=1 to 4-i? &有一个空格 Endfor For j=1
5、 to i?* Endfor ?Endfor13. 判断一个整数是否素数CleaInpu x= to xFor i=2 to x-1 If mod(x,i)0Loop ElseExitEndifEndforIf ix-1 ?x,是素数Else ?x,不是素数Endif14. 判断十个整数是否素数CleaFor j=1 to 10Inpu x= to xFor i=2 to x-1 If mod(x,i)0Loop ElseExitEndifEndforIf ix-1 ?x,是素数Else ?x,不是素数EndifEndfor15. 找出两个数的大数和小数CleaInpu x= to xInpu
6、 y to yIf xy ?x,大,y,小Else ?y,大,x,小Endif16. 找出三个数的最大数和最小数CleaInpu x= to xInpu y to yInpu z to zIf xy t=xx=yy=tElse If xz t=xx=zz=t endifendifif yz t=yy=zz=tendif?x,是最大数,z,是最小数17. 找出十个数的最大数和最小数CleaDime a(10)For i=1 to 10 Inpu to a(i)EndforMax=a(1)Min=a(1)For i=2 to 10 If maxa(i) Min=a(i)Endif EndifEnd
7、for?max,min18. 找出23矩阵中的最大数和最小数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,1)min=a(1,1)for i=1 to 2 for j=1 to 3if max a(I,j) min= a(I,j) endifendif endforendfor?max=,max,min=,min19. 对三个整数从大到小排序ClearInput a= to aInput b= to bInput c= to cIf ab
8、 T=a A=b B=tElse If ac t=a A=cc=t endifendifIf bc T=b A=c c=tendif?a,b,c20. 对十个整数从大到小排序(用选择法和起泡法两种方法)选择法: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 maxa(j) max=a(j) Num=jEndif Endfor If inum t=A(i) a(i)=a(num) a(num)=t EndifEndforFor i=1 to 10 ?a(i)
9、, Endfor起泡法:ClearDime a(10)For i=1 to 10 Input to a(i)EndforFor i=1 to 9 For j=1 to 10-i If a(j)c and a+cb and b+ca p=(a+b+c)/2 s=sqrt(p*(p-a)*(p-b)*(p-c) ?selse ?三边不能组成三角形Endif27. 求二元方程的根(分三种情况:两个不等实根,两个相等实根,无实根)cleainpu a= to a &a0inpu b= to b &b0inpu c= to ci=b*b-4*a*c if i0 ?方程无实根! else if i=0 r
10、=(-b)/(2*a) ?方程有两个相等实数根:,r else x1=(-b+sqrt(i)/(2*a) x2=(-b-sqrt(i)/(2*a) ?方程有两个不相等实数根:,x1,x2 endifendif28. 输入任意一个五位整数,前后对应位置上的数据进行交换重新排列(即逆序排列)(例: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)
11、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矩阵的“鞍点”,即该位置上的元素在该行上最大,在该列上最小(也有可能没有鞍点)cleadime 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 maxa(k,col) min=a(k,col) row=k endif endfor if max=min ?a(row,col),是鞍点,在,row,行,col,列 flag=.f. endifendforif flag=.t. ?无鞍点endif30. 求S(n)=a+aa+aaa+.+aaa.aaa(其中有n个a)之值,a是一个数字,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?s