VF编程题库

  • 格式:doc
  • 大小:97.00 KB
  • 文档页数:10

第六章 程序设计编程题 1. 求园的面积(要求判断半径是否合理) Clea Inpu „r=‟ to r If r>0 S=3.14*r*r ?s Else ?‟半径错误!‟ Endif

2. 求分段函数Y的值

Clea Inpu „x=‟ to x If x>0 Y=2*x+5 Else If x=0 Y=x Else Y=abs(x) Endif Endif ?y

3. 输入一个百分制成绩判断其等级(优/良/中/及格/不及格) Clea Inpu „cj=‟ to cj Do case Case cj>=90 ?‟优‟ Case cj>=80 ?‟良‟ Case cj>=70 ?‟中‟ Case cj>=60 ?‟及格‟ Orth ?‟不及格‟ Endcase

4. 输入若干个(个数不定)百分制成绩判断其等级(优/良/中/及格/不及格) Clea Inpu „请输入处理几个人的成绩:‟ to n For i=1 to n Inpu „cj=‟ to cj Do case Case cj>=90 ?‟优‟ Case cj>=80 ?‟良‟ Case cj>=70 ?‟中‟ Case cj>=60 ?‟及格‟ Orth ?‟不及格‟ Endcase endfor

5. 求S=1+2+3. . . . . .+100

Y= 2x+5 x>0 x x=0 | x | x<0 Clea S=0 For i=1 to 100 S=s+i Endfor ?s

6. 求S=1×2×3. . . . . .×100 Clea p=1 For i=1 to 100 p=p*i Endfor ?p

7. 求S=1+3+5.. . . . .+99 Clea S=0 For i=1 to 99 step 2 S=s+i Endfor ?s

8. 求S=1-2+3-4. . . . . .-100 Clea S=0 For i=1 to 100 S=s+(-1)^(i+1)*i Endfor ?s

9. 求S=1+1/2+2/3+3/5. . . . . .前10项之和 Clea S=0 A=1 B=1 For i=1 to 10 S=s+a/b T=a A=b B=t+b Endfor ?s

10. 求S=1!+2!+3!. . . . . .+10! Clea S=0 P=1 For i=1 to 10 P=p*i S=s+p Endfor ?s

11. 对学生表中所有入学成绩≥650分的学生免去贷款 Clea Use 学生 Scan for入学成绩>=650 .and. 贷款否=.t. Repl贷款否 with .f. Endscan Use 12. 输出图形

Clea For i=1 to 4 For j=1 to i ??‟*‟ Endfor ? Endfor Clea For i=1 to 4 For j=1 to 4-i ??‟ ‟ &&有一个空格 Endfor For j=1 to 2*i-1 ??‟*‟ Endfor ? Endfor

Clea For i=1 to 4 For j=1 to 4-i ??‟ ‟ &&有一个空格 Endfor For j=1 to i ??‟*‟ Endfor ? Endfor

13. 判断一个整数是否素数 Clea Inpu „x=‟ to x For i=2 to x-1 If mod(x,i)<>0 Loop Else Exit Endif Endfor If i>x-1 ?x,‟是素数‟ Else ?x,‟不是素数‟ Endif

14. 判断十个整数是否素数 Clea For j=1 to 10

* **** * ******* * **** ** *** *** ***** ** *** *** ** ***** *** *** ** **** * ******* * **** * Inpu „x=‟ to x For i=2 to x-1 If mod(x,i)<>0 Loop Else Exit Endif Endfor If i>x-1 ?x,‟是素数‟ Else ?x,‟不是素数‟ Endif Endfor

15. 找出两个数的大数和小数 Clea Inpu „x=‟ to x Inpu „y‟ to y If x>y ?x,‟大‟,y,‟小‟ Else ?y,‟大‟,x,‟小‟ Endif

16. 找出三个数的最大数和最小数 Clea Inpu „x=‟ to x Inpu „y‟ to y Inpu „z‟ to z If xz=t endif endif if yt=y y=z z=t endif ?x,‟是最大数‟,z,‟是最小数‟

17. 找出十个数的最大数和最小数 Clea Dime a(10) For i=1 to 10 Inpu to a(i) Endfor Max=a(1) Min=a(1) For i=2 to 10 If maxElse If min>a(i) Min=a(i) Endif Endif Endfor ?max,min

18. 找出2×3矩阵中的最大数和最小数 clea dime a(2,3) for i=1 to 2 for j=1 to 3 input „a(„+str(I,2)+‟,‟+str(j,2)+‟)=‟ to a(I,j) endfor endfor max=a(1,1) min=a(1,1) for i=1 to 2 for j=1 to 3 if maxmax= a(I,j) else if min> a(I,j) min= a(I,j) endif endif endfor endfor ?‟max=‟,max,‟min=‟,min

19. 对三个整数从大到小排序 Clear Input „a=‟ to a Input „b=‟ to b Input „c=‟ to c If ac=t endif endif If bT=b A=c c=t endif ?a,b,c

20. 对十个整数从大到小排序(用选择法和起泡法两种方法) 选择法: Clear Dime a(10) For i=1 to 10 Input to a(i) Endfor For i=1 to 9 Max=a(i) Num=i For j=i+1 to 10 If maxEndfor If i<>num t=A(i) a(i)=a(num) a(num)=t Endif Endfor For i=1 to 10 ??a(i),' ' Endfor

起泡法: Clear Dime a(10) For i=1 to 10 Input to a(i) Endfor For i=1 to 9 For j=1 to 10-i If a(j)a(j+1)=t Endif endfor Endfor For i=1 to 10 ??a(i),' ' Endfor

21. 输出Fibonacci(斐波那契)数列的前十项 Clear Dime a(10) a(1)=1 a(2)=1 For i=3 to 10 a(i)=a(i-1)+a(i-2) Endfor For i=1 to 10 ??A(i) Endfor

22. 输出杨辉三角的前十行 Clear Dime a(10,10) For i=1 to 10 A(I,1)=1 A(I,i)=1 Endfor For i=3 to 10 For j=2 to i-1 A(I,j)=a(i-1,j)+a(i-1,j-1) Endfor Endfor For i=1 to 10 For j=1 to i ??A(I,j) Endfor ? Endfor

23. 对2×3矩阵转置 Clea Dime a(2,3),b(3,2) for i=1 to 2 for j=1 to 3 input to a(I,j) endfor endfor for i=1 to 3 for j=1 to 2 b(I,j)=a(j,i) endfor endfor for i=1 to 3 for j=1 to 2 ??b(I,j) Endfor ? endfor

24. 求三位数中的所有水仙花数(即指一个三位数,其各位数字立方和等于该数本身) Clea for 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 ?x Endif endfor

25. 求100以内的所有完数(即一个数恰好等于除它本身外的所有因子之和) Clea for 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 endif endfor

26. 已知三角形的三边(从键盘输入),求其面积(S^2=p(p-a)(p-b)(p-c), p=(a+b+c)/2) Clea input 'a=' to a