QBasic编程题!

来源:百度知道 编辑:UC知道 时间:2024/05/26 07:37:25
1.给出100个数,找出最大值
2.求算式的结果:1-1/3+1/5-1/7+1/9
两道题都用if……then(分支结构)或for i= ……to……这两种语言编写,也可以结合起来编写,谢谢大家了!!!

1、
DIM A(100)
FOR I=1 TO 100
INPUT A(I)
NEXT I
(你没说有没有赋值,我就当没赋值了)
FOR I=1 TO 100
IF MAX<A(I) THEN MAX=A(I)
NEXT I
PRINT MAX

2、
S=1
X=1
FOR I=1 TO 4
X=X+2
S=S-1/X
NEXT I
PRINT S

第一题
cls
dim a(100)
for i=1 to 100
input a(i)
next i
for i=1 to 99
for j=i+1 to 100
if a(i)<a(j) then swap a(i),a(j)
next j,i
?a(1)
end

第二题
cls
f=-1:s=0
for i=1 to 9 step 2
if f then s=s+1/i else s=s-1/i
f=not(f)
next i
?s
end

cls
for i =1 to 100
input a(i)
next i
for i =1 to 100
if max<a(i) then max=a(i)
next
print max

(1)
cls
dim a(100)
max=0
for i=1 to 100
input a(i)
if a(i)>max then max=a(i)
next i
? max
end

(2)
cls
for i=1 to 9 step 2
s=