习题1.3

定义一个过程,它以三个数为参数,返回其中较大的两个数的平方和.

(Define a procedure thats three numbers as argument and return the sum of the square of two large number.)

scheme实现

(define (square x)
(* x x))
(define (sum_of_square x y)
(+ (square x)
(square y)))
(define (bigger x y)
(if (> x y)
x
y))
(define (smaller x y)
(if (< x y)
x
y))
(define (sum_square x y z)
(sum_of_square (bigger x y)
(bigger (smaller x y) z)))

c语言实现

//用C语言实现scip(计算机程序构造与解释)的一些习题。对比并进一步了解scheme的函数式思想
//Define a procedure thats three numbers as argument and return the sum of the square of two large
//numbers.
//C language implementation #include "stdafx.h"
#include<iostream>
using namespace std; int square(int x);
int sum_of_square(int a, int b);
int bigger_num(int a, int b);
int two_more_bigger_sum_of_square(int a, int b, int c);
int smaller_num(int a, int b); //check the code
int main()
{
cout<<two_more_bigger_sum_of_square(,,);
return ;
}
int square(int x) {
return x*x;
} //retun the sum of the num of square
int sum_of_square(int a, int b) {
return square(a)+square(b); } //return the bigger num
int bigger_num(int a, int b) {
if (a > b)
return a;
else
return b;
} //takes the two num as agrument and return the smaller num
int smaller_num(int a, int b) { //return the bigger num
if (a > b)
return b;
else
return a;
}

scip习题(1) scheme和c实现的对比的更多相关文章

  1. the little schemer 笔记(0)

    the little schemer 笔记 Z.X.L 2012年08月13日 五项规则 car的规则car只对非空列表有定义. cdr的规则cdr只对非空列表有定义.任何非空列表的cdr是另外一个列 ...

  2. SCIP读书笔记(1)

    这书也算是必修吧,尤其是我这种非科班人员,还是应该抽时间尽量学习一下.大致翻过一遍,习题非常多,尽力吧. ##构造过程抽象 * 为了表述认知,每种语言都提供了三种机制:基本元素:组合方式:抽象方法. ...

  3. SICP 习题 (1.10)解题总结

    SICP 习题 1.10 讲的是一个叫“Akermann函数”的东西,去百度查可以查到对应的中文翻译,叫“阿克曼函数”. 就像前面的解题总结中提到的,我是一个数学恐惧者,看着稍微复杂一点的什么函数我就 ...

  4. scip学习

    最近在学习scip  准备把里面比较有价值的题分别用lisp和c语言写出来.这样或许能更加深入的理scheme的函数式编程. tip:我用的c语言环境是vs2015,lisp环境为Drracket;

  5. 开始学习Scheme

    开始学习Scheme   函数式编程(Functional Programming)是在MIT研究人工智能(Artificial Intelligence)时发明的,其编程语言为Lisp.确切地说,L ...

  6. Python 函数习题

    #encoding=utf-8 from urllib.request import urlopen import random import os ''' 1. 定义一个fuc(url, folde ...

  7. SCIP:构造过程抽象--面向对象的解释

    心智的活动,除了尽力产生各种简单的认知之外,主要表现为如下三个方面:(1)将若干简单认知组合为一个复合的认识,由此产出各种复杂的认知.(2)将两个认知放在一起对照,不管他们如何简单或者复杂,在这样做时 ...

  8. Partition:Partiton Scheme是否指定Next Used?

    在SQL Server中,为Partition Scheme多次指定Next Used,不会出错,最后一次指定的FileGroup是Partition Scheme的Next Used,建议,在执行P ...

  9. Android业务组件化之URL Scheme使用

    前言: 最近公司业务发展迅速,单一的项目工程不再适合公司发展需要,所以开始推进公司APP业务组件化,很荣幸自己能够牵头做这件事,经过研究实现组件化的通信方案通过URL Scheme,所以想着现在还是在 ...

随机推荐

  1. 加密算法 MD5/SHA1

    近来想学习函数式编程. 但是一直不知道怎么展开这个学习过程,目前的研究进度也不深入,想讲解一些原理也无从下手. 先简单的上一些算法,逐步分析语法和思想.虽然程度不深,但至少能记录这个过程. 本例子用F ...

  2. 代码阅读软件kscope源码安装指导

    安装 kscope-1.6.2 1. ./configure --without-arts --prefix=/soft/kscope-1.6.2  (I customize the installi ...

  3. linux $ 类型变量 及Makefile 中 $ 类型变量的含义

    Shell 命令中: $$: shell pid $!: pid of the last process running in shell $?: shell command return code ...

  4. SQLSERVER数据库学习总结七(视图,索引)

    --视图的主意点:不能和表的名称相同,如果某一列为函数,表达式,常量或者与来自多张表的列名相同,必须为列定义名称,不能在试图上创建索引 if exists(select 1 from sys.syso ...

  5. 原生Js 两种方法实现页面关键字高亮显示

    原生Js 两种方法实现页面关键字高亮显示 上网看了看别人写的,不是兼容问题就是代码繁琐,自己琢磨了一下用两种方法都可以实现,各有利弊. 方法一 依靠正则表达式修改 1.获取obj的html2.统一替换 ...

  6. Django ORM 查询管理器

    Django ORM 查询管理器 ORM 查询管理器 对于 ORM 定义: 对象关系映射, Object Relational Mapping, ORM, 是一种程序设计技术,用于实现面向对象编程语言 ...

  7. TD中{text-overflow:ellipsis;} 用法

    Styles: table{ table-layout:fixed; } table td{ text-overflow:ellipsis;overflow:hidden;white-space: n ...

  8. [转]Inspecting Obj-C parameters in gdb

    Since the addition of i386 and x86_64 to the Mac OS’s repertoire several years back, remembering whi ...

  9. 【编程范式】C语言1

    最近在网易公开课上看斯坦福大学的<编程范式>,外国人讲课思路就是清晰,上了几节课,感觉难度确实比我们普通大学大很多,但是却很有趣,让人能边学边想. 范式编程,交换两个数,利用 void * ...

  10. Asp.Net请求响应过程

    Asp.Net请求响应过程 在之前,我们写了自己的Asp.Net框架,对整个流程有了一个大概的认识.这次我们来看一下Asp.Net整个请求处理过程是怎么样的. 浏览器封装请求报文,发送请求到达服务器, ...