2.1

Posted ...............洋葱的秋秋空间........

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.1相关的知识,希望对你有一定的参考价值。

(define (make-rat n d)
  (let ((g (gcd n d)))
    (cons (/ n g) (/ d g))))

(define (numer x) (car x))
(define (denom x) (cdr x))

(define (print-rat x)
  (newline)
  (cond ((= (denom x) 1) (display (numer x)))
      ((display (numer x))
      (display "/")
      (display (denom x)))
      ))

(define (add-rat x y)
  (make-rat (+ (* (numer x) (denom y))
               (* (numer y) (denom x)))
            (* (denom x) (denom y))
            ))

(define (sub-rat x y)
  (make-rat (- (* (numer x) (denom y))
               (* (numer y) (denom x)))
            (* (denom x) (denom y))
            ))

(define (mul-rat x y)
  (make-rat (* (numer x) (numer y))
            (* (denom x) (denom y))))

(define (div-rat x y)
  (make-rat (* (numer x) (denom y))
            (* (denom x) (numer y))))

(define (equal-rat? x y)
  (newline)
  (= (* (numer x) (denom y))
     (* (denom x) (numer y))))

(define one-half (make-rat 1 2))
(print-rat one-half)

(define one-third (make-rat 1 3))
(print-rat one-third)

(print-rat (add-rat one-half one-third))
(print-rat (mul-rat one-half one-third))
(print-rat (sub-rat one-half one-third))
(print-rat (div-rat one-half one-third))
(equal-rat? one-half one-third)
(print-rat (add-rat one-third one-third))
(print-rat (make-rat 2 1))
(print-rat (make-rat 4 2))
(print-rat (make-rat 2 2))


;2.1
(print-rat (sub-rat one-third one-half))
(print-rat (sub-rat one-third one-third))

 

以上是关于2.1的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript笔试题(js高级代码片段)

连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段

全栈编程系列SpringBoot整合Shiro(含KickoutSessionControlFilter并发在线人数控制以及不生效问题配置启动异常No SecurityManager...)(代码片段

day06-jsp

SpringCloud系列十一:SpringCloudStream(SpringCloudStream 简介创建消息生产者创建消息消费者自定义消息通道分组与持久化设置 RoutingKey)(代码片段

如何使控制台中的视图缓存片段过期?