主题:找位置
TMGY119
[专家分:0] 发布于 2007-09-08 10:18:00
输入一个整数X,将X插入到一列有序数据:-5,3,4,12,20,45,70中,并使数据序列仍有序,试求X应插入的位置.
回复列表 (共6个回复)
沙发
Matodied [专家分:7560] 发布于 2007-09-08 11:24:00
CLS
INPUT x
DATA -5,3,4,12,20,45,70
DIM a(8)
FOR i = 1 TO 7: READ a(i): NEXT i
FOR i = 1 TO 7
IF x < a(i) THEN EXIT FOR
NEXT i
IF i <= 7 THEN PRINT i ELSE PRINT 8
END
别忘了加分!!
板凳
TMGY119 [专家分:0] 发布于 2007-09-08 15:15:00
[em8][em4][em13][em2][em3]知道了.[em12]加分加分!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3 楼
TMGY119 [专家分:0] 发布于 2007-09-08 15:37:00
IF x < a(i) THEN EXIT FOR 如果换种格式,应该怎样写.我不太习惯这样写.还有
IF i <= 7 THEN PRINT i ELSE PRINT 8 这种格式也不太明白.
本人系一笨鸟,略深奥点就看不懂了.还有其它法吗
4 楼
snoopy7 [专家分:70] 发布于 2007-09-08 18:59:00
CLS
INPUT x
DATA -5,3,4,12,20,45,70
i = 0
DO
READ a(i)
IF x < a(i) THEN f = -1
i = i + 1
LOOP UNTIL f OR i > 6
IF i = 7 AND a(i - 1) < x THEN i = i + 1
PRINT i;
END
[em3][em4][em5][em6][em7][em8][em9][em10][em11][em12][em13][em14][em15][em16][em17][em18][em19][em20][em39][em36][em64][em73][em71]
5 楼
snoopy7 [专家分:70] 发布于 2007-09-08 19:00:00
加分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6 楼
网虫一号 [专家分:1230] 发布于 2007-09-21 17:22:00
CLS
INPUT N
FOR I = 1 TO 7: READ A(I): NEXT i
FOR I = 1 TO 7
IF N < A(I) THEN EXIT FOR
NEXT I
IF I <= 7 THEN PRINT I ELSE PRINT 8
DATA -5,3,4,12,20,45,70
END
我来回复