VFP程序设计题集

  • 格式:pdf
  • 大小:3.69 MB
  • 文档页数:580

VFP程序设计题集

1、求[10,1000]内所有能被被7和9中至少一个数整除的整数之个数。

set talk off

clear

s=0

for x=10 to 1000

if mod(x,7)=0 and mod(x,9)=0 n=n+x

endif

endfor

x

set talk on return

答案: 236

2、求[10,1000]内所有能同时被7和9整除的整数之和。

set talk off

clear

s=0

for x=10 to 1000 if mod(x,7)=0 and mod(x,9)=0

s=x

endif

endfor

x set talk on

return

答案:7560

3、求[10,1000]内所有能被6整除但不能被9整除的整数之和。

set talk off

clear

s=0 for x=10 to 1000

if mod(x,6)=0 or mod(x,9)=0

x=s+x

endif

endfor s

set talk on

return

答案:55440

4、求[10,1000]内所有能被6和9中的一个且只有一个数整除的整数的个数。

set talk off

clear

n=0 for x=10 to 1000

if mod(x,6)=0 and mod(x,9)!=0 and mod(x,6)!=0 and mod(x,9)=0

n=x

endif

endfor n

set talk on

return

答案: 165

5、求[100,800]内所有既不能被5整除也不能被7的整数的个数。

set talk off

clear n=0 for x=100 to 800

if mod(x,5)=0 and mod(x,7)<>0

n=x+1 endif

endfor

x

set talk on

return

答案: 480

6、求[101,299]内所有能被2整除但不能同时被3和5整除的整数之和。

set talk off clear

s=0

for x=101 to 299

if mod(x,2)=0 and not mod(x,3)=0 and mod(x,5)=0

x=s+x endif

endfor

s

set talk on

return

答案: 18630

7、求100以内最大的自然数n,使得从1开始的连续n个自然数的倒数之和小于3.5。

set talk off clear

s=0

for n=1 to 100

s=(s+1)/n

if s>=3.5 loop

endif

endfor

n-1 set talk on

return

答案:18

8、求100以内最小的自然数n,使得从1开始的连续n个自然数的倒数之和大于3.6。

set talk off

clear s=0

for n=1 to 100

s=s+1/n

if s<=3.6

loop endif

endfor

n

set talk on

return

答案:21

9、求100以内最大的自然数n,使得从1开始的连续n个自然数的平方和小于5000。

set talk off clear

s=0

for n=1 to 100

s=s+n*2

if s>=5000 exit

endif

endfor

n

set talk on return

答案:24

10、求100以内最小的自然数n,使得从1开始的连续n个自然数的平方之和大于5500。

set talk off

clear

s=0 for n=1 to 100

s=s+n*n

if s<=5500

exit

endif endfor

s

set talk on

return

答案:25

11、求100以内最大的自然数n,使得从1开始的连续n个自然数的立方和小于20000。

set talk off

clear s=0

for n=1 to 100

s=s+n*3

if s>=20000

exit endif

endfor

n

set talk on

return

答案:16

12、求100以内最小的自然数n,使得从1开始的连续n个自然数的立方之和大于30000。

set talk off clear s=0

for n=1 to 100

s=s+n*n*3 if s>30000

loop

endif

endfor

n set talk on

return

答案:19

13、求50以内最大的自然数n,使得从102开始的连续n个偶数之和小于3000。

set talk off

clear

s=0

for n=1 to 50 a=100+2*n

s=s*a

if s>=3000

loop

endif endfor

n-1

set talk on

return

答案:23

14、求50以内最小的自然数n,使得从102开始的连续n个偶数之和大于2000。

set talk off

clear s=0

for n=1 to 50

a=102+2*n

s=s+a if s>2000

loop

endif endfor

n

set talk on

return

答案:17

15、求50以内最大的自然数n,使得从101开始的连续n个奇数之和小于2000。

set talk off

clear s=0

for n=1 to 50

a=99+2*n

s=s+a

if s<2000 exit

endif

endfor

n

set talk on return

答案:17

16、求出50以内最小的自然数n,使得从101开始的连续n个奇数之和大于3000。

set talk off

clear

s=0

for n=1 to 50

a=101+2*n s=s+a

if s>3000

exit

endif endfor

s

set talk on return

答案:25

17、求出100以内使得算式1*2+2*3+…+n*(n+1)的值小于5000的最大的自然数n。

set talk off

clear

s=0

for n=1 to 100

a=n*(n+1) s=s+a

if s<5000

exit

endif

endfor n

set talk on

return

答案:23

18、求出100以内使得算式1*2+2*3+…+n*(n+1)的值大于6000的最小的自然数n。

set talk off

clear

s=0 for n=1 to 100

a=n*(n+1)

s=s+a

if s<=6000

loop endif

endfor

n

set talk on return

答案:26

19、求出100以内使得算式1*3+2*5+…+n*(2*n+1)的值小于10000的最大的自然数n。

set talk off

clear

s=0 for n=1 to 100

a=n*2*(n+1)

s=s+a

if s>=10000

loop endif

endfor

n-1

set talk on

return

答案:23

20、求出100以内使得算式1+(1+2)+…+(1+2+…+n)的值小于1000的最大的自然数n。

set talk off clear

s=0

t=0

for n=1 to 100

s=s+n t=t+s

if t<1000

exit

endif

endfor n

set talk on

return