主题:进制问题50分
1054122
[专家分:750] 发布于 2009-07-24 13:26:00
输入m,n。
输入一个m进制的数,把它转换成为n进制的数
回复列表 (共9个回复)
沙发
gewenbo [专家分:450] 发布于 2009-08-03 15:39:00
DECLARE SUB inpu () : DECLARE SUB Sort () : inpu
SUB inpu
CLS : PRINT : INPUT "Perform time = ", pt
FOR i = 1 TO pt: PRINT : Sort: NEXT i
END SUB
SUB Sort
INPUT "N, JinZhi = ", n$, m
IF m < 2 OR m > 16 THEN PRINT "Data Error(Number system < 2 or > 16)!": END
n$ = UCASE$(LTRIM$(RTRIM$(n$)))
IF m = 10 THEN t = VAL(n$): GOTO tiao
FOR i = 1 TO LEN(n$)
IF m >= 10 THEN
IF MID$(n$, i, 1) >= CHR$(65 + (m - 10)) THEN PRINT "Data Error!": END
ELSE
IF VAL(MID$(n$, i, 1)) >= m THEN PRINT "Data Error(Syntax Error)!": END
END IF
NEXT i: i = 0
s = INSTR(n$, "."): t = 0
IF s = 0 THEN a$ = n$
IF s <> 0 THEN a$ = LEFT$(n$, s - 1): b$ = MID$(n$, s + 1)
FOR i = 1 TO LEN(a$)
IF MID$(a$, i, 1) >= "0" AND MID$(a$, i, 1) <= "9" THEN
t = t + VAL(MID$(a$, i, 1)) * m ^ (LEN(a$) - i)
ELSE
t = t + (ASC(MID$(a$, i, 1)) - 55) * m ^ (LEN(a$) - i)
END IF
NEXT i
IF s <> 0 THEN
FOR i = 1 TO LEN(b$)
IF MID$(b$, i, 1) >= "0" AND MID$(b$, i, 1) <= "9" THEN
t = t + VAL(MID$(b$, i, 1)) * m ^ (-i)
ELSE
PRINT "Data Error(In the decimal fraction find letter)!": END
END IF
NEXT i
END IF
tiao: INPUT "ZhuanHuan = ", zh
IF zh < 2 OR zh > 16 THEN PRINT "Data Error(Number system < 2 or > 16)!"
PRINT "("; n$; ")"; LTRIM$(RTRIM$(STR$(m)));
IF zh = m THEN PRINT "=("; LTRIM$(RTRIM$(n$)); ")"; LTRIM$(RTRIM$(STR$(m))): END
IF m <> 10 THEN PRINT "="; "("; LTRIM$(RTRIM$(STR$(t))); ")10";
IF zh = 10 THEN PRINT : END
ys = t - INT(t): t = INT(t)
DO
asd = t MOD zh: t = t \ zh
IF asd < 10 THEN
js$ = LTRIM$(RTRIM$(STR$(asd))) + js$
ELSE
asd = asd - 10: js$ = CHR$(65 + asd) + js$
END IF
LOOP UNTIL t = 0
IF ys <> 0 AND ys <> INT(ys) THEN
js$ = js$ + "."
FOR i = 1 TO 5
ys = ys * zh
js$ = js$ + LTRIM$(RTRIM$(STR$(INT(ys)))): ys = ys - INT(ys)
IF ys = INT(ys) THEN GOTO pr
NEXT i
f = -1
END IF
pr: PRINT "=("; js$; ")"; LTRIM$(RTRIM$(STR$(zh)))
IF f = -1 THEN PRINT "Not nicety"
END
END SUB
板凳
梦幻小樱 [专家分:140] 发布于 2009-08-06 12:52:00
DECLARE SUB inpu () : DECLARE SUB Sort () : inpu
SUB inpu
CLS : PRINT : INPUT "Perform time = ", pt
FOR i = 1 TO pt: PRINT : Sort: NEXT i
END SUB
SUB Sort
INPUT "N, JinZhi = ", n$, m
IF m < 2 OR m > 16 THEN PRINT "Data Error(Number system < 2 or > 16)!": END
n$ = UCASE$(LTRIM$(RTRIM$(n$)))
IF m = 10 THEN t = VAL(n$): GOTO tiao
FOR i = 1 TO LEN(n$)
IF m >= 10 THEN
IF MID$(n$, i, 1) >= CHR$(65 + (m - 10)) THEN PRINT "Data Error!": END
ELSE
IF VAL(MID$(n$, i, 1)) >= m THEN PRINT "Data Error(Syntax Error)!": END
END IF
NEXT i: i = 0
s = INSTR(n$, "."): t = 0
IF s = 0 THEN a$ = n$
IF s <> 0 THEN a$ = LEFT$(n$, s - 1): b$ = MID$(n$, s + 1)
FOR i = 1 TO LEN(a$)
IF MID$(a$, i, 1) >= "0" AND MID$(a$, i, 1) <= "9" THEN
t = t + VAL(MID$(a$, i, 1)) * m ^ (LEN(a$) - i)
ELSE
t = t + (ASC(MID$(a$, i, 1)) - 55) * m ^ (LEN(a$) - i)
END IF
NEXT i
IF s <> 0 THEN
FOR i = 1 TO LEN(b$)
IF MID$(b$, i, 1) >= "0" AND MID$(b$, i, 1) <= "9" THEN
t = t + VAL(MID$(b$, i, 1)) * m ^ (-i)
ELSE
PRINT "Data Error(In the decimal fraction find letter)!": END
END IF
NEXT i
END IF
tiao: INPUT "ZhuanHuan = ", zh
IF zh < 2 OR zh > 16 THEN PRINT "Data Error(Number system < 2 or > 16)!"
PRINT "("; n$; ")"; LTRIM$(RTRIM$(STR$(m)));
IF zh = m THEN PRINT "=("; LTRIM$(RTRIM$(n$)); ")"; LTRIM$(RTRIM$(STR$(m))): END
IF m <> 10 THEN PRINT "="; "("; LTRIM$(RTRIM$(STR$(t))); ")10";
IF zh = 10 THEN PRINT : END
ys = t - INT(t): t = INT(t)
DO
asd = t MOD zh: t = t \ zh
IF asd < 10 THEN
js$ = LTRIM$(RTRIM$(STR$(asd))) + js$
ELSE
asd = asd - 10: js$ = CHR$(65 + asd) + js$
END IF
LOOP UNTIL t = 0
IF ys <> 0 AND ys <> INT(ys) THEN
js$ = js$ + "."
FOR i = 1 TO 5
ys = ys * zh
js$ = js$ + LTRIM$(RTRIM$(STR$(INT(ys)))): ys = ys - INT(ys)
IF ys = INT(ys) THEN GOTO pr
NEXT i
f = -1
END IF
pr: PRINT "=("; js$; ")"; LTRIM$(RTRIM$(STR$(zh)))
IF f THEN PRINT "Not nicety"
END
END SUB
4 楼
gewenbo [专家分:450] 发布于 2009-08-08 18:46:00
“梦幻小樱”严重抄袭!!!小心我告你!!
5 楼
phile [专家分:2310] 发布于 2009-08-09 14:21:00
唉,梦幻小樱简直是天下第一抄袭
6 楼
天天和和 [专家分:1420] 发布于 2009-08-14 22:17:00
在这里不应该抄袭
应该以自己的实力去得分
7 楼
天天和和 [专家分:1420] 发布于 2009-08-14 22:18:00
楼主
这题应该输入三个数吧
8 楼
天天和和 [专家分:1420] 发布于 2009-08-14 22:23:00
00 CLS
10 DIM A(100), A1(100), B(20)
20 INPUT "X,M,P="; X, M, P
30 PRINT X, M, P
40 IF X < 0 THEN X = ABS(X): SIG = -1
50 IX = FIX(X)
60 I = 1
70 A(I) = IX MOD M
80 IX = IX \ M
90 IF IX = 0 THEN 120
100 I = I + 1
110 GOTO 70
120 K = I: P = M ^ (-P)
130 FOR K1 = 1 TO K
140 A1(K1) = A(I)
150 I = I - 1
160 NEXT
170 Y = X - FIX(X)
180 J = 1
190 B(J) = FIX(M * Y)
200 Y = Y * M - B(J)
210 IF (Y / M ^ J < P) THEN 240
220 J = J + 1
230 GOTO 190
240 IF SIG = -1 THEN PRINT "-";
250 GOSUB 320
260 PRINT ".";
270 FOR I = 1 TO J
280 A1(I) = B(I)
290 NEXT: K = J
300 GOSUB 320
310 END
320 FOR I = 1 TO K
330 IF A1(I) <= 9 THEN PRINT A1(I);
340 IF A1(I) = 10 THEN PRINT "A";
350 IF A1(I) = 11 THEN PRINT "B";
360 IF A1(I) = 12 THEN PRINT "C";
370 IF A1(I) = 13 THEN PRINT "D";
380 IF A1(I) = 14 THEN PRINT "E";
390 IF A1(I) = 15 THEN PRINT "F";
400 NEXT
410 RETURN
X 要转化的数 M要转化的进制 P原进制
9 楼
phile [专家分:2310] 发布于 2009-08-17 13:57:00
天天和和,我佩服你!
我来回复