2012甘肃专升本计算机程序设计

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

2012甘肃专升本计算机程序设计

1、求解AX+BX+C=0的根、其中A、B、C三个参数由键盘输入。一元二次方程的求根公式是:X=-b±√b²-4ac/2a

clear

text

一元二次方程求解

ax^2+bx+c=0

endtext

input "请输入a的值:" to a

input "请输入b的值:" to b

input "请输入c的值:" to c

m=b*b-4*a*c

if m>=0

x1=(-b+sqrt(m))/(2*a)

x2=(-b-sqrt(m))/(2*a)

?"x1的值是:",x1

?"x2的值是:",x2

else

?"此方程无实根!"

endif

2、编写程序将1-100之间所有能被7和3整除的整数输出

clear

for i=1 to 100

if i%3=0 and i%7=0

??i

endif

endfor

3、编写程序计算e,e的近似值计算公式为:e=1+1/1!+1/2!+1/3!+...+1/n!,直到1/n!<0.000001为止

clear

e=1

n=1

do while .t.

k=1

for i=1 to n

k=k*i

endfor

m=1/k

e=e+m

if m<0.000001

exit

endif

n=n+1

enddo

?"e=1+1/1!+1/2!+1/3!+…+1/n!=",e

4、编写程序,计算1!+2!+3!+.......N!=?

clear

input "请输入n的值:" to n

s=0

t=1

for i=1 to n

t=t*i

s=s+t

endfor

?"1!+2!+3!+.......N!=",s

5、从键盘输入十个数,将它们进行降序排列。

clear

dime a(10)

for i=1 to 10

input "请输入一个数:" to a(i)

endfor

?"降序排列为:"

for i=1 to 9

for j=i+1 to 10

if a(i)

k=a(i)

a(i)=a(j)

a(j)=k

endif

endfor

??alltrim(str(a(i)))+" "

endfor

??alltrim(str(a(i)))

6、(1)输出有*号组成的图形:

*

***

*****

*******

*****

***

*

clear

for i=-3 to 3

?space(abs(i))

for j=1 to 7-abs(i)*2

??"*"

endfor

endfor

(2)

*

***

*****

*******

*********

clear

for i=1 to 5

?space(5-i)

for j=1 to 2*i-1

??"*"

endfor

endfor

7、编写一个程序产生一个有20项的Fibonacci数列并输出。注:Fibonacci数列的前两项为1,从第三项开始每一项是其前两项只和。

clear

a=1

b=1

??a,b

for i=1 to 18

c=a+b

a=b

b=c

??c

endfor

8、九九乘法表

clear

for i=1 to 9

for j=1 to i

??alltrim(str(i))+"*"+alltrim(str (j))+"="+alltrim(str(i*j))+space(3) endfor

?

Endfor

9、显示1-100之间的所有素数,并求它们的和。

clear

s=0

??"1到100之间的素数为:"

for i=2 to 100

x=0

for j=2 to i-1

if i/j=int(i/j)

x=1

endif

endfor

if x=0

??alltrim(str(i))+" "

s=s+i

endif

endfor

?"它们的和是:",s

10、求100到999之间的水仙花数。

clear

?"100-999之间的水仙花数有:"

for i=100 to 999

k=int(i/100)

m=(int(i/10))%10

n=i%10

if k^3+m^3+n^3=i

??alltrim(str(i))+space(2)

endif

endfor

11、从键盘输入10个数,找出其中的最大数和最小数。

clear

input "请输入第1个数:" to a

k=a

for i=2 to 10

input "请输入第"+alltrim(str(i))+"个数:" to b

if a

a=b

endif

if k>b

k=b

endif

endfor

?"其中最大的数是:",a

?"其中最小的数是:",k

12、从键盘输入一个字符串,统计其中各个字符的个数,包括数字,大小写英文字母和特殊字符。

clear

accept "请输入一串字符:" to x

store 0 to dyw,xyw,kg,sz,qt

m=len(x)

for i=1 to m

x1=substr(x,i,1)

k=asc(x1)

do case

case k=32

kg=kg+1

case k>=48 and k<=57

sz=sz+1

case k>=65 and k<=90

dyw=dyw+1

case k>=97 and k<=122 xyw=xyw+1

other

qt=qt+1

endcase

endfor

?"其中空格有: "+alltrim(str(kg))+"个" ?"大写字母有: "+alltrim(str(dyw))+"个"

?"小写字母有: "+alltrim(str(xyw))+"个"

?"数字有: "+alltrim(str(sz))+"个" ?"其它字符有: "+alltrim(str(qt))+"个"

13、输入一个十进制数,将它转换为二进制数并显示出来。

clear

s=""

input "请输入一个十进制数:" to a do while a>0

b=a%2

a=int(a/2)

s=alltrim(str(b))+s

enddo

?"转换为二进制为:",s

14、VFP编程:有一个3×4的矩阵,要求编程求出其中值最大的那个元素的值,以及其所在的位置。

clear

dime a(3,4)

for i=1 to 3

for j=1 to 4

input "请输入一个值:" to

a(i,j)

endfor

endfor

k=a(1,1)

for m=1 to 3

for n=1 to 4

r=a(m,n)

相关文档
最新文档