Chinaunix首页 | 论坛 | 博客
  • 博客访问: 209292
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: LINUX

2011-11-18 11:13:30

  1. ;; mht created on Nov 15, 2011

  2. ;; average-price : list-of-numbers -> number
  3. (define (average-price a-list-of-nums)
  4.   (cond
  5.     [(empty? a-list-of-nums) 0]
  6.     [else
  7.      (/ (sum-price a-list-of-nums)
  8.         (count-price a-list-of-nums))]))

  9. ;; sum-price : list-of-nums -> number
  10. (define (sum-price a-list-of-nums)
  11.   (cond
  12.     [(empty? a-list-of-nums) 0]
  13.     [else
  14.      (+ (first a-list-of-nums)
  15.         (sum-price (rest a-list-of-nums)))]))

  16. ;; count-price : list-of-nums -> number
  17. (define (count-price a-list-of-nums)
  18.   (cond
  19.     [(empty? a-list-of-nums) 0]
  20.     [else
  21.      (+ (count-price (rest a-list-of-nums))
  22.         1)]))

  23. ;; test
  24. (average-price (cons 2 (cons 3 (cons 1 empty))))
  25. (average-price (cons 2 empty))
阅读(176) | 评论(0) | 转发(0) |
0

上一篇:exam9.5.6

下一篇:exam9.5.8

给主人留下些什么吧!~~