第1类题目:
求在某范围内的,满足被某数整除的数的个数(或这些数的和)
如:[1]编程序求出100到800之间同时满足除4余1和除5余3条件的数的个数。 clear n=0
for i=100 to 800
if mod(i,4)=1 and mod(i,5)=3 n=n+1 endif endfor ?n
[2]编程序,计算在0至70的范围内有多少个数,其每位数的乘积小于每位数的和。 clear n=0
for i=10 to 70 a=int(i/10) b=i if a*b
[3]编程序求出1到100之间同时满足除3余2和除4余2条件的数的和。 clear s=0
for i=1 to 100
if mod(i,3)=2 and mod(i,4)=2 s=s+i endif endfor ?s
[4]编程序求出1-600以内的能被5整除的数的平方和。 set talk off clear s=0
for i=1 to 600 if mod(i,5)=0 s=s+i*i endif endfor ?s
[5]编写程序,统计区间[1000,9999]内所有能被6整除,且千位数字与个位数字之和为5的整数的个数。clear n=0
for a=1 to 9
for b=0 to 9 for c=0 to 9
26
for d=0 to 9
i=a*1000+b*100+c*10+d if mod(i,6)=0 and a+d=5 n=n+1 endif endfor endfor endfor endfor ?n
第2类题目:求阶乘数之和,或阶乘 如:[1] s=1!+2!+3!+....+10! clear s=0 t=1 i=1
for i=1 to 10
t=t*i s=s+t endfor ?s
[2] 1!+2!+3!+....+n! 当s大于61000时结束累加,求n clear s=0 t=1 i=1
do while .t.
t=t*i s=s+t if s>6100 exit endif i=i+1 enddo ?i
[3] 2!+4!+6!....+10! clear s=0 t=1 i=1
for i=1 to 10
t=t*i
if mod(i,2)=0 s=s+t endif endfor ?s
[4] 3!+5!+7!+....+9!
27
clear s=0 t=1 i=1
for i=1 to 10
t=t*i
if mod(i,2)=1 and i>=3 s=s+t endif endfor ?s
[5]求15! clear s=0
for i=1 to 15
s=s*i endfor ?s
第3类题目:求某范围内的数据之和,当累加数大于某个数时,累加结束
[1]下面和程序是求1+3+5+7+9+11+?这样的奇数之和.若累加数大于10000时,则结束累加。 clear s=0 i=1
do while .t. s=s+i
if s>10000 exit endif i=i+2 enddo ?s
[2]设S=1+1/2+1/3+...+1/N,N为正整数。编程求使S不超过8的最大的N。 clear s=0 i=1
do while .t. s=s+1/i if s>8 exit endif i=i+1 enddo ?i-1
[3]设S=1+1/2+1/3+...+1/N,N为正整数。编程求当算到100项时S的值为多少?精确到小数点后两位。set talk off clear s=0
for i=1 to 100
28
s=s+1/i endfor
?str(s,10,2)
[4]编写程序,求出1到5000 之间能被3整除的前若干个奇数之和,当和大于 2000 时程序退出。 clear s=0
for i=1 to 5000 step 2 if mod(i,3)=0 s=s+i endif if s>2000 exit endif endfor ? s
[5]编写程序,求3+6+12+24+48+ ?之和。当累加和大于500时终止累加,输出此时的和。 clear s=0 i=3
do while .t. s=s+i if s>500 exit endif i=i*2 enddo ?s
第三类题目:实际应用题目
[1]把30元钱分成一元、二元和五元的纸币且纸币数共为15张的分法有多少种?(注:在兑换中一元、二元、五元的纸币数可以为0)。 clear n=0
for one=0 to 15
for two=0 to 15 for five=0 to 6
if one+two+five=15 and one+two*2+five*5=30 n=n+1 endif endfor endfor endfor ?n
[2]有35个学生一起买小吃,共花钱100元,其中每个大学生花4元,每个中学生花2元,每个小学生花1元,问大、中、小学生的人数分配共有多少种不同的解(去掉某类学生为0的解)? clear n=0
for a=1 to 35
29
for b=1 to 35 for c=1 to 35
if a+b+c=35 and a*4+b*2+c*1=100 n=n+1 endif endfor endfor endfor ?n
第四类题目
[1]已知a>b>c,且a+b+c<30,求满足条件1/(a^2)+1/(b^2)=1/(c^2)的共有多少组。 clear n=0
for a=1 to 29
for b=1 to a-1 for c=1 to b-1
if a+b+c<30 and 1/a^2+1/b^2=1/c^2 n=n+1 endif next next next ?n
[2]编写程序,求200到800之间素数的个数。 方法1:
clear 方法2:
Clear n=0 n=0
for x=200 to 800
for i=200 to 800 flag=.t.
for j=2 to i-1
for i=2 to x-1 if mod(I,j)=0
exit if x%i=0 endif
flag=.f.
endfor exit
if i=j
endif n=n+1
endif next endfor
if flag=.t.
?n n=n+1 endif next ?n
[3]编写程序,求共有几组I、j、k符合算式ijk+kji=2333,其中I、j、k是0~9之间的一位整数。clear n=0
for i=0 to 9 for j=0 to 9 for k=0 to 9
if (i*100+j*10+k)+(k*100+j*10+i)=2333 n=n+1
30
endif next next next ?n
编写程序,统计1000~9999之间的所有满足以下条件的四位数的个数。该四位数是一个完全平方数,其第1位与第3位数字之和为10,第2位与第4位数字之积为12。 clear n=0
for i=1000 to 9999
for j=1 to int(sqrt(i)) a=int(i/1000) b=int(i/100)-a*10
c=int(i/10)-a*100-b*10 d=i
if i=j*j and a+c=10 and b*d=12 n=n+1 endif endfor endfor
?n
31