主题:求救!!!!!
firestorm11
[专家分:50] 发布于 2006-12-05 16:58:00
有5个数,a1=4,a2=6,a3=2,a4=0,a5=3
找出最大数并输出编号
例如a5最大则输出5
多谢!
回复列表 (共6个回复)
沙发
sixth [专家分:0] 发布于 2006-12-15 09:05:00
这个也好做。
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
板凳
雪光风剑 [专家分:27190] 发布于 2006-12-16 18:32:00
[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 楼
雪光风剑 [专家分:27190] 发布于 2006-12-16 18:37:00
其实可以只用一个循环
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
5 楼
星月神ming [专家分:180] 发布于 2007-01-05 09:16:00
6 楼
星月神ming [专家分:180] 发布于 2007-01-05 09:21:00
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]看看行不行,不行去问高手
我来回复