主题:幽灵密码,帮帮我!!!
火拳艾斯
[专家分:0] 发布于 2011-03-24 21:18:00
帮帮我,我要做高精度加减乘除,而且要n进制.
回复列表 (共9个回复)
沙发
火拳艾斯 [专家分:0] 发布于 2011-03-24 21:20:00
就是输入一个n进制,然后再输入两个数,要加减乘除!
板凳
幽灵密码 [专家分:3510] 发布于 2011-04-22 21:58:00
你先查一下普通的高精度,算完以后改一下啊。可以在后面加上一段十进制转二进制的程序,别告诉我你不会
3 楼
幽灵密码 [专家分:3510] 发布于 2011-05-19 19:20:00
把大于等于10什么的改成你要的n进制
比如说2进制加法程序段
For i = 1 To l1
a(i) = a(i) + b(i)
a(i + 1) = a(i + 1) + a(i) \ n
a(i) = a(i) mod n
Next i
l1是排列后第一个字符串的长度
n是进制
我没调试,你看看行不行
4 楼
幽灵密码 [专家分:3510] 发布于 2011-05-19 19:45:00
N进制高精度加法程序:
CLS
DO
INPUT "Input n=", n
f = 1
IF n > 11 OR n < 2 THEN f = 0: GOTO 1
INPUT "Input a,b=", a$, b$
la = LEN(a$)
lb = LEN(b$)
IF la < lb THEN SWAP a$, b$: SWAP la, lb
y = la + 1
REDIM a(y), b(y)
FOR i = 1 TO la
a(y - i) = VAL(MID$(a$, i, 1))
IF a(y - i) >= n THEN f = 0: GOTO 1
NEXT i
FOR i = 1 TO lb
b(lb + 1 - i) = VAL(MID$(b$, i, 1))
IF b(lb + 1 - i) >= n THEN f = 0: GOTO 1
NEXT i
1
LOOP UNTIL f = 1
FOR i = 1 TO la
a(i) = a(i) + b(i)
a(i + 1) = a(i + 1) + a(i) \ n
a(i) = a(i) MOD n
NEXT i
IF a(y) = 0 THEN y = y - 1
PRINT "a+b=";
FOR i = y TO 1 STEP -1
PRINT USING "#"; a(i);
NEXT i
END
5 楼
幽灵密码 [专家分:3510] 发布于 2011-05-19 20:18:00
N进制高精度减法:
CLS
DO
INPUT "Input n=", n
f = 1
p$ = ""
IF n > 11 OR n < 2 THEN f = 0: GOTO 1
INPUT "Input a,b=", a$, b$
la = LEN(a$)
lb = LEN(b$)
IF (a$ < b$) AND (la <= lb) THEN SWAP a$, b$: SWAP la, lb: p$ = "-"
y = la + 1
REDIM a(y), b(y), c(y + 1)
FOR i = 1 TO la
a(la + 1 - i) = VAL(MID$(a$, i, 1))
IF a(la + 1 - i) >= n THEN f = 0: GOTO 1
NEXT i
FOR i = 1 TO lb
b(lb + 1 - i) = VAL(MID$(b$, i, 1))
IF b(lb + 1 - i) >= n THEN f = 0: GOTO 1
NEXT i
1
LOOP UNTIL f = 1
FOR i = 1 TO la
IF a(i) < b(i) THEN a(i) = a(i) + n: a(i + 1) = a(i + 1) - 1
c(i) = a(i) - b(i)
NEXT i
DO WHILE c(y) = 0
y = y - 1
LOOP
PRINT "a-b="; p$;
FOR i = y TO 1 STEP -1
PRINT USING "#"; c(i);
NEXT i
END
6 楼
幽灵密码 [专家分:3510] 发布于 2011-05-19 20:36:00
N进制乘法:
CLS
DO
INPUT "Input n=", n
f = 1
IF n > 11 OR n < 2 THEN f = 0: GOTO 1
INPUT "Input a,b=", a$, b$
la = LEN(a$)
lb = LEN(b$)
IF la < lb THEN SWAP a$, b$: SWAP la, lb
y = la + lb
REDIM a(la), b(lb), c(y)
FOR i = 1 TO la
a(la + 1 - i) = VAL(MID$(a$, i, 1))
IF a(la + 1 - i) >= n THEN f = 0: GOTO 1
NEXT i
FOR i = 1 TO lb
b(lb + 1 - i) = VAL(MID$(b$, i, 1))
IF b(lb + 1 - i) >= n THEN f = 0: GOTO 1
NEXT i
1
LOOP UNTIL f = 1
FOR i = 1 TO la
FOR j = 1 TO lb
x = a(i) * b(j)
t = i + j - 1
c(t) = c(t) + x MOD n
c(t + 1) = c(t + 1) + c(t) \ n + x \ n
c(t) = c(t) MOD n
NEXT j, i
DO WHILE c(y) = 0
y = y - 1
LOOP
PRINT "a*b=";
FOR i = y TO 1 STEP -1
PRINT USING "#"; c(i);
NEXT i
END
7 楼
火拳艾斯 [专家分:0] 发布于 2011-05-23 19:34:00
好-----厉-------害---------!羡慕
8 楼
905482852 [专家分:380] 发布于 2011-06-19 15:37:00
发现幽灵密码最近的人气比较高,最近在研究星座,难道是幽灵密码的人气来了?并不是说不支持幽灵密码,但是moz要加油了。
9 楼
moz [专家分:37620] 发布于 2011-06-20 00:19:00
又关我事?
我来回复