2015-11-04 43 views
-3
(define hmaxDigit 
    (lambda (n b) 
    (cond 
     ((< n 10) n) 
     ((> n (* 10 b)) (hmaxDigit n (* b 10))) 
     ((< 10 (remainder b)) 
     ((> (quotient n b) (remainder n b)) (quotient n b)) 
     ((< (quotient n b) (remainder n b)) (remainder n b))))) 

這是我的,但它只適用於2位數字。如何找到數字中最大的數字?球拍

+0

輸出整數中最大的數字 – Oniichan

回答

1
If n<10 then n is the_maximum_digit 
else the_maximum_digit is the maximum of 
           the first_digit and 
           the maximum of the remaining digits. 

(define (maximum-digit n) 
    (cond 
    [(< n 10) n] 
    [else  (max (first-digit n) (maximum-digit (remaining-digits n)))])) 

詳細信息,如first-digitremaining-digits需要填寫。