习题中有个题是:
利用repeat循环,提示用户输入a,b值后,自动将他们从小到大连乘,并将结果显示。
问题:代码运行发现当大数在21以上就会出现连乘值为负数的问题,例如a=3,b=22,结果xx=-261357568.
请各位高人指点。谢谢
(defun c:t72-1() ;提示用户输入两个数值,自动从小到大累计连乘 (setq a (getint "请输入整数起始值:")) (setq b (getint "请输入整数结束值值:")) (if (< a b) (progn (setq nums a) (setq nume b) ) (progn (setq nums b) (setq nume a) ) ) (setq xx 1) (setq n (+ 1 (- nume nums))) (setq xxadd nums) (repeat n (setq xx (* xx xxadd)) (setq xxadd (1+ xxadd)) ) ;本句改写(princ "\n总和sum=:") (princ sum) (setq str1 (strcat (itoa nums) "到")) (setq str2 (strcat (itoa nume) "连乘值=" )) (setq str3 (strcat (itoa xx))) (alert (strcat str1 str2 str3)) (prin1) ) (prompt "<t72-1>repeat循环连乘用法范例") (prin1) |