回 帖 发 新 帖 刷新版面

主题:求救!!!!!

有5个数,a1=4,a2=6,a3=2,a4=0,a5=3
找出最大数并输出编号
例如a5最大则输出5
多谢!

回复列表 (共6个回复)

沙发

这个也好做。
for i=1 to 5
input a(i)
next i
x=a(1)
max=1
for i=2 to 5
if x<a(i) then swap x,a(i) : max=i
next i
print "最大数是:";x,"其编号为:";max
end

板凳

[quote]这个也好做。
for i=1 to 5
input a(i)
next i
x=a(1)
max=1
for i=2 to 5
if x<a(i) then swap x,a(i) : max=i
next i
print "最大数是:";x,"其编号为:";max
end
[/quote]
做错了……
不应该是swap,而是直接x=a(i)

3 楼

其实可以只用一个循环
input "please input the 1 number",x
max=1
for i=2 to 5
  print "please input the ",i," number",
  input y
  if x<y then x=y:max=i
next i
print "the max number is",x," ,it's the ",max," number"
end

4 楼

哦,谢谢了

5 楼


6 楼


for i=1 to 5
input a(i)
next i
max=a(1)
for j=2 to 5
if a(j)>max then 
f=j
max=a(j)
endif
print f,a(f)

[em2]看看行不行,不行去问高手

我来回复

您尚未登录,请登录后再回复。点此登录或注册