当前位置:文档之家› 黑龙江省二vfp计算机考试程序设计题库

黑龙江省二vfp计算机考试程序设计题库

4.2. 1表操作题
78统计出rsda.dbf表中职称为“工程师”的人数,
Use rsda , store 0 to s , locate for 职称=“工程师” , do while not eof() , s=s+1 , continue , enddo
461 计算机等级考试成绩 笔试和上机均大于等于80 优秀
Use student , do while .not.eof() , if 笔试>=80 and 上机>=80 , REPL 等级 with“优秀” , endif , skip , enddo , list
462 由工资表。Dbf 按性别汇总工资
Use 工资表 , index on 性别 to sy , total on 性别 to 汇总.dbf fildes 工资 , use 汇总 , list
4.2.2求和题:
437计算num的各位上的数字之和,将结果存入变量out中,用DO WHILE实现。
s=0 , DO WHILE num<>0, s=s+num%10, num=int(num/10), enddo , out=s , ?out.
457求p=1-1/(2*2)+1/(3*3)-1/(4*4)+1/(5*5)结果存在out中,用 DO WHILE实现
P=0, M=1, DO WHILE M<=5 , P=P+((-1)^(M+1))/(M*M), M=M+1, ENDDO , ?"P=",P ,OUT=P
414求p=1+1/(2*2)+1/(3*3)+````````1/(10*10)将结果存入变量out中,用DO WHILE实现
P=0, M=1, DO WHILE M<=10 , P=P+1/(M*M) , M=M+1 , ENDDO , ?”P=”,P , OUT=P
73输出10到50之间所有能被7整除的数(用do while实现)并将这些数存入out中
i=10 , S=0 , do while i<=50 , if i%7=0 , ?i , S=S+i , endif , i=i+1 , enddo , OUT=s
79用子程序求出1~15之间的能被3整除的整数的平方和。将结果存入变量OUT中,要求用for循环实现。
N=1 , S=0 , FOR N=1 TO 15 , IF N%3=0 , S=S+N*N , ENDIF , ENDFOR , ?S , SET TALK ON , OUT=S
86用循环求出1~15之间能被3整除的整数的阶乘和存入变量out中,要求用for循环语句
T=1 , FOR N=1 TO 15 , T=T*N , IF N%3=0 , OUT=OUT+T , ENDIF , ENDFOR , ?OUT
87从键盘输入一个整数,输出所有能整除该数,并且本身也能被3整除的数的和。(eg 输入6,输出3,6)结果存于变量x中,要求用for实现。
FOR N=1 TO A , IF A%N=0.AND.N%3=0 , ?N , x=x+N , ENDIF , ENDFOR
71求出并显示3!+4!+5!的值,将结果存入变量out中,要求用for编程。
S=0 , FOR I=3 TO 5 , p=1 , FOR J=1 TO I , p=p*J , ENDFOR , S=S+p , endfor , ?“3!+4!+5!的值是:”,s , OUT=S
93求1~200间的所有偶数的和,结果输入变量OUT中,要求用for循环语句实现。
S=0 , FOR I=1TO 200 , IF I/2=INT(I/2) , S=S+I , ENDIF , ENDFOR , ?S , OUT=S
97编程打印一数列,前两个数是0、1,第三个数是前两个数之和,以后每个数都是其前两个数之和。编程求出第20个数,将结果存入out中,要求用for循环语句实现
a=0 , B=1 , for i=3 to 20 , c=a+b , a=b , b=c , endfor , ?”c=”,c , out=c
455编程求sum=3-33+333-3333+33333
S=0 , t=0 , d=3 , for i=1 to 5 , t=t+d , s=s+t*(-1)^(i+1) , d=d*10 , endfor , out=s , ? out
454求 sum=1/3+1/33+1/333+1/3333+1/333

33
S=0 , t=0 , d=3 , for i=1 to 5 , t=t+d , s=s+1/t , d=d*10 , endfor , out=s , ? out
450fibonacci 数列第28项的值。第一项为1,第二项也为1,。。。。。。。。。
Store 1 to f1,f2 , f=f1+f2 , for i=3 to 27 , f1=f2 , f2=f , f=f1+f2 , endfor , out=f , ? out
449 s=2/1+3/2+5/3+8/5+13/8+21/13+34/21
f1=1 , f2=1 , s=0 , for i=1 to 7 , f3=f1+f2 , f1=f2 , f2=f3 , s=s+f2/f1 , endfor , out=s , ? out
444 a1=1 , a2=1/(1+a1) , a3=1/(1+a2) ……..an=1/(1+a(n-1))当n=10 ,求s=a1+a2+…….+a10
a=1 , s=1 , for i=1 to 9 , a=1.0/(1+a) , s=s+a , endfor , out=s , ? out
445 a1=1 , a2=1/(1+a1) , a3=1/(1+a2) ……..an=1/(1+a(n-1))当n=10 ,求s=a1-a2+a3-a4…….-a10
a=1 , s=1 , for i=1 to 9 , a=1.0/(1+a) , s=s+a*(-1)^i , endfor , out=s , ? out
435 sum=3+33+333+3333+33333+333333
S=0 , t=0 , d=3 , for i=1 to 5 , t=t+d , s=s+t , d=d*10 , endfor , out=s , ? out
431 分数序列2/1, 3/2,5/3,8/5,13/8,21/13……..前20项之和
F1=1 , f2=1 , s=0 , for i=1 to 20 , f3=f1+f2 , f1=f2 , f2=f3 , s=s+f2/f1 , endfor , out=s , ? out
422 a1=1 , a2=1/(1+a1) , a3=1/(1+a2) ……..an=1/(1+a(n-1)) 求a10
a=1 , for i=1 to 9 , a=1.0/(1+a) , endfor , out=s , ? out
427 y=1-1/3+1/5-1/7+1/9
S=1 , for i=1 to 4 , s=s+(-1)^i/(2*i+1) , endfor , out=s , ? out
428y=1-1/2+1/4-1/6+1/8-1/10
S=1 , for i=1 to 5 , s=s+(-1)^i/(2*i) , endfor , out=s , ? out
4.2.4最大(小)值
77任意数三个数从大到小排序
If x94输入三个数找出最大和最小
Ma=a , mi=a , if b>a , ma=b , endif , if mi>b , mi=b , endif , if mac , mi=c , endif
439求1*1+2*2+。。。。。。。。+n*n<=1000中满足条件的最大的n
S=0 , n=1 , do while s<=1000 , n=n+1 , s=s+n*n , enddo , out=n-1 , ? out
4.2.5字符处理类
74在屏幕上纵向输出"计算机等级考试"。
S=”计算机等级考试” , i=1 , do while i<14 , ?”SUBS(S,I,2)” , IF I=9 , Y=SUBS(S,I,2) , endif , i=i+2 , enddo
91输入一个三位数,将个十百位顺序拆开分别存入变量s中,用加号分隔。如输入345分开后为 要求用dowhile 实现。
do while n>10 , a=n%10 , s=”+”+str(int(a),1)+s , n=n-a , n=n/10 , enddo , s=subs(s,2,len(s))
426编程统计一个长度为2的字符串在另一个字符串中出现的次数。例如。。。。将结果存入out中要求用dowhile实现
I=0 , n=0 , do while i<=len(str1)-1 , if str2=substr(str1,I,2) , n=n+1 , endif i=i+1 , enddo , out=n , ? out
85从键盘输入一个汉字

字符串,送入变量s中,将它逆向存入变量Y中,如:输入"计算机考试",输出为"试考机算计",要求用for循环实现。
For n=1 to len(s)-1 step 2 , y=y+subs(s,len(s)-n,2) , endfor
416过滤已存在字符串变量str中的内容,只保留串中的字母字符,并统计新生成串中包含的字母个数。将生成的结果字符串存入变量out中。
N=len(str) , L=0 , S=”” , for i=1 to n , if substr(str,i,1)<=’Z’ and substr(str,i,1)>=’A’ or substr(str,i,1)<=’z’ and substr(str,i,1)>=’a’ , L=L+1 , S=S+ substr(str,i,1) , endif , endfor , ?”s=”,s , out=s
456编程将一个由四个数字组成的字符串转换为每两个数字间有一个字符"*"的形式输出。例如输入"4567",应输出"4*5*6*7"。将结果存入变量out中。
Spc=”*” , s=”” , for i=1 to len(str)-1 , s=s+ substr(str,i,1)+spc , endfor , s=s+ substr(str,i,1) , out=s , ? out,len(out)
436编程将一个由四个数字组成的字符串转换为每两个数字间有一个空格的形式输出。例如输入"4567",应输出"4 5 6 7",将结果存入变量out中,要求用for循环语句实现。
Spc=space(1) , s=”” , for i=1 to len(str)-1 , s=s+ substr(str,i,1)+spc , endfor , s=s+ substr(str,i,1) , out=s , ? out,len(out)
4.2.6图形题
92计算并在屏幕上显示乘法表,将各部分结果相加存入变量z中,要求用dowhile实现。
X=1 , ? , do while x<=9 , y=1 , do while y<=x , ??str(y,1)+’x’+str(x,1)+’=’+str(x*y,2)+’’ , z=z+x*y , y=y+1 , enddo , ? , x=x+1 , enddo
75输出图形* ** *** ****(要求使用for语句,利用双重循环语句)要求:将第三行的所有字符存入变量s中
For i=1 to 4 , for j=1 to i , ??”*” , endfor , ? , endfor
82利用循环程序输出图形:1 222. 33333. 4444444并将输出第三行存入变量s中。
N=1 , for n=1 to 4 , ?space(4-n) , for m=1 to 2*n-1 , ??str(n,1) , endfor , endfor , set talk on , s=”33333”
84利用循环输出图形:4 333 22222 1111111并将最后一行存入变量s中。
For n=1 to 4 , ?space(4-n) , for m=1 to 2*n-1 , ??str(4-n+1,1) , endfor , endfor , s=”1111111”
4.2.7数组题
452求max-min=
Store array(1) to max,min , for i=1 to 10 , if array(i)>max , max=array(i) , endif , if array(i)451求max+min
Store array(1) to max,min , for i=1 to 10 , if array(i)>max , max=array(i) , endif , if array(i)446找出正整数中的最小的偶数,
M=100 , for i=1 to 10 , if array(i)%2=0 , if min>array(i) , min=array(i) , endif , endif , endfor , out=min , ? out
447找出正整数中的最小的奇数,
Min=array(1) , for i=1 to 10 , if array(i)%2!

=0 , if min>array(i) , min=array(i) , endif , endif , endfor , out=min , ? out
448找出正整数中的最大的奇数,
Max=array(1) , for i=1 to 10 , if array(i)%2!=0 , if max453 求max*min
Store array(1) to max,min , for i=1 to 10 , if array(i)>max , max=array(i) , endif , if array(i)429求一组数中大于平均值的个数
S=0 , for i=1 to 10 , s=s+array(i) , endfor , s=s/10 , n=0 , for j=1 to 10 , if array(j)>s , n=n+1 , endif , endfor , out=n , ? out
430找出正整数中的最大的偶数,
Max=array(1) , for i=1 to 10 , if array(i)%2=0 , if max4.2.8其他类
69输入三角形的边长,输入边长满足两边之和大于第三边,且为正值。计算并输出三角形的面积s;若不满足以上条件,显示输出"不能构成三角形"。将面积值存入变量area中。
S=(a+b+c)/2 , if a+b>c and b+c>a and a+c>b and a>0 and b>0 and c>0 , area=sqrt(s*(s-a)*(s-b)*(s-c)) , else , ? "不能构成三角形" , area=-1 , endif
72 编程求p_-1*(1*2)*(1*2*3)*........*(1*2*3*.....*N).
P=1 , for i=1 to n , q=1 , for j=1 to i , q=q*j , endfor , p=p*q , endfor , out=p
80从键盘输入一个数,如果该数字大于0,通过子程序输出该数字作为半径的圆面积;如果该数字小于等于0,则输出"不能作为圆的半径"。将结果存入变量out中
If a>0 , out=a*a*3.14 , else , out= -1 , endif
166计算下列分段函数:当输入x时,显示输出y 要求用docase实现
Do case , case x<1 , y=x*3 , cae x>=1 and x<10 , y=x^2 , otherwise , y=7*x-4 , endcase , ?y
415判断一个三位数是否为"水仙花数",输出判断结果。是为1,否为0。
Bw=int(n/100) , sw=int((n-bw*100)/10) , gw=n%10 , if n= bw*bw*bw+ sw*sw*sw+ gw*gw*gw , out=1 , else , out=0 , endif , ? out
418判断整数w的各位数字平方之和能否被5整除,可以则返回1,否则返回0
S=0 , do while w>0 , s=s+(w%10)*(w%10) , w=int(w/10) , enddo , if s %5=0 , out=1 , else , out=0 , endif , ? out
419求一个大于10的n位整数的后n-1位的数
N=0 , i=1 , do while (w>10) , n=n+i*(w%10) , w=int(w/10) , i=i*10 , enddo , ? n , out=n
420求对某一正数的值保留两位小树,并对第三位进行四舍五入,
i=0 , i=int((h*1000)%10) , if i>=5 , out=(h*100+1)/100 , else , out=int(h*100)/100 , endif , ? out
423求自然数345各位数字的积
S=1 , do while n>0 , d=n%10 , s=s*t , n=int(n/10) , enddo , out=s , ? out
432 fibonacci 数列前28项的和。第一项为1,第二项也为1,。。。。。。。。。
Store 1 to f1,f2 , f=f1+f2 ,

for i=3 to 28 , k=k+f , f1=f2 , f2=f , endfor , out=k , ? out
434变量x为不超过五位的正整数,求x的位数
Do case , case x>9999 , place=5 ,case x>999 , place=4 ,case x>99 , place=3 , case x>9 , place=2 , otherwise , place=1 , endcase , out=place , ? out
438求一个整数,它加上一百后是一个完全平方数,再加上168有事一个完全平方数
i=1 , do while i<100000 , x=int(sqrt(i+100)) , y=int(sqrt(i+268)) , if x*x=i+100 and y*y=i+268 , exit , endif , i=i+1 , enddo , out=I , ? out
443求对某一正数的值保留3位小数,并对第四位进行四舍五入,
i=0 , i=int((h*10000)%10) , if i>=5 , out=(h*1000+1)/1000 , else , out=int(h*1000)/1000 , endif , ? out
458 计算正整数num的各位上的数字之积,
S=1 , do while num<>0 , s=s*(NUM%10) , NUM=INT(NUM/10) , enddo , out=s , ? out







相关主题
文本预览
相关文档 最新文档