全国计算机等级二级QBASIC上机编程题题型
发布时间:2006-10-14 8:53:32   收集提供:gaoqian
 第1题

编制程序PROG1.BAS其功能是:计算表达式1!+2!+3!+...+k!,计算k=6时的值。请根据程序的需要将函数FACT补充完整。

Prog1.bas

DECLARE FUNCTION FACT(t)

OPEN "QB12.DAT" FOR OUTPUT AS #1

sum = 0

INPUT k

FOR i = 1 TO k

 sum = sum + FACT(i)

NEXT

PRINT "sum="; sum

PRINT #1, sum

CLOSE #1

END


FUNCTION FACT(t)



END FUNCTION

编程题参考答案程序
 DECLARE FUNCTION FACT (t)
OPEN "QB12.DAT" FOR OUTPUT AS #1
sum = 0
INPUT k
FOR i = 1 TO k
sum = sum + FACT(i)
NEXT
PRINT "sum="; sum
PRINT #1, sum
CLOSE #1
END

FUNCTION FACT (t)
mm = 1
FOR j = 1 TO t
mm = mm * j
NEXT
FACT = mm
END FUNCTION



第2题
编制程序PROG1.BAS其功能是:求 1*5*10*15*...*30 的准确值,将结果保存在文件QB22.DAT中。请将程序补充完整。

OPEN "QB22.DAT" FOR OUTPUT AS #1

DIM t AS LONG

参考答案程序

OPEN "QB22.DAT" FOR OUTPUT AS #1
DIM t AS LONG
CLS
t = 1
FOR i = 5 TO 30 STEP 5
t = t * i
PRINT i
NEXT
PRINT t
PRINT #1, t
CLOSE #1
END



 第3题
编制程序PROG1.BAS其功能是:求自然对数的底e 的近似值。其前十项的计算公式为:
e(10)=1+1+1/(1*2)+1/(1*2*3)+...+1/(1*2*3*...*10)

请在程序的【1】、【2】和【3】处填写适当的内容。

Prog1.bas

e = 【1】

t= 1

FOR j = 1 TO 10

 t = t/【2】

 e = e + t

NEXT j

PRINT 【3】

END

参考程序答案
e = 1
t= 1
FOR j = 1 TO 10
t = t/j
e = e + t
NEXT j
PRINT e
END

第4题

编制程序PROG1.BAS其功能是:求下式和s=a+aa+aaa+…+a…a,

其中a表示0至9间一个数字。计算a=8时4项和,写到文件"QB42.DAT"

中。请编写函数item实现此功能。

Prog1.bas

DECLARE FUNCTION item(a,k)

a = 8: n = 4

FOR j = 1 TO n

 sum = sum + item(a,j)

NEXT j

PRINT "Sum=";sum

OPEN "QB42.DAT" FOR OUTPUT AS #1

PRINT #1, sum

CLOSE #1

END






FUNCTION item(a,k)


END FUNCTION

参考程序答案



DECLARE FUNCTION item (a, k)
a = 8: n = 4
FOR j = 1 TO n
sum = sum + item(a, j)
NEXT j
PRINT "Sum="; sum
OPEN "QB42.DAT" FOR OUTPUT AS #1
PRINT #1, sum
CLOSE #1
END

FUNCTION item (a, k)
mm = a
FOR i = 2 TO k
mm = mm * 10 + a
NEXT
item = mm
END FUNCTION


第5题

编制程序PROG1.BAS其功能是:打印下列图形。

A

AAA

AAAAA

AAAAAAA

BBBBBBB

BBBBB

BBB

B

请在程序的【1】、【2】和【3】处填写适当的内容。

Prog1.bas

FOR K=1 TO 4

 FOR J=1 TO 2*K-1

 PRINT 【1】

 NEXT J

 PRINT

NEXT K

FOR K=4 TO 1 【2】

 FOR J=1 TO K*2-1

 PRINT 【3】

 NEXT J

 PRINT

NEXT K

END

参考程序答案

FOR K=1 TO 4
FOR J=1 TO 2*K-1
PRINT "A";
NEXT J
PRINT
NEXT K
FOR K=4 TO 1 STEP -1
FOR J=1 TO K*2-1
PRINT "B";
NEXT J
PRINT
NEXT K
END

第6题
编制程序PROG1.BAS其功能是:从成绩文件"GRADE.TXT"中读入若干学生某一门课的成绩,计算并输出其平均值。

程序有【1】、【2】及【3】三处需要补充完整。请将程序调试出所需结果。

Prog1.bas

OPEN "GRADE.TXT" FOR INPUT AS #1

DO WHILE NOT EOF(1)

 【1】 #1,G

 N=N+1

 S=S+G

【2】

CLOSE #1

S=S/【3】

PRINT "Mean=";S

END

参考程序答案
 OPEN "GRADE.TXT" FOR INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1,G
N=N+1
S=S+G
LOOP
CLOSE #1
S=S/N
PRINT "Mean=";S
END



































 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50