- 6
- 0
- 约6.76万字
- 约 9页
- 2016-12-22 发布于贵州
- 举报
1、求解AX+BX+C=0的根、其中A、B、C三个参数由键盘输入。一元二次方程的求根公式是:X=-b±√b2-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为止
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 m0.000001
exit
endif
n=n+1
enddo
?e=1+1/1!+1/2!+1/3!+…+1/n!=,e
4、编写程序,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)a(j)
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 ab
a=b
endif
if kb
原创力文档

文档评论(0)