习题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. Linq无聊练习系列2--select/distinct练习

    void dataBindByWhere()        { /**************select/distinct 练习*******************/            //获 ...

  2. HttpClient 检索与获取过程数据

    使用 HttpClient 检索与获取过程数据   对于System.Net.Http的学习(一)——System.Net.Http 简介 对于System.Net.Http的学习(二)——使用 Ht ...

  3. Hadoop 从URL中读取数据

    package com.hadoop; import java.io.IOException; import java.io.InputStream; import java.net.URL; imp ...

  4. SQLSERVER清空(Truncate)被外键引用的数据表

    前言:我们知道SQLSERVER清空数据表有两种方式Delete和Truncate,当然两者的不同大家也都知道(不清楚的可以MSDN).不过这个错误“Cannot truncate table  be ...

  5. SAX解析xml浅析

    SAX解析XML文件采用事件驱动的方式进行,也就是说,SAX是逐行扫描文件,遇到符合条件的设定条件后就会触发特定的事件,回调你写好的事件处理程序.使用SAX的优势在于其解析速度较快,占用内存较少(相对 ...

  6. Bootstrap3入门

    Bootstrap3学习第一轮(入门) 前言 在上一节中http://www.cnblogs.com/aehyok/p/3381651.html主要是简单的介绍了一下Bootstrap.从http:/ ...

  7. js中内置有对象

    statpot:使用mongo+bootstrap+highcharts做统计报表 最近做了一个统计项目,这个统计项目大致的需求是统计接口的访问速度.客户端会调用一个接口来记录接口的访问情况,我的需求 ...

  8. Weka开发[2]-分类器类

    这次介绍如何利用weka里的类对数据集进行分类,要对数据集进行分类,第一步要指定数据集中哪一列做为类别,如果这一步忘记了(事实上经常会忘记)会出现“Class index is negative (n ...

  9. 目标HttpController在ASP.NET Web API中是如何被激活的:目标HttpController的创建

    目标HttpController在ASP.NET Web API中是如何被激活的:目标HttpController的创建 通过上面的介绍我们知道利用HttpControllerSelector可以根据 ...

  10. java常用的环境变量配置

    JDK配置 JAVA_HOME: C:\java\jdk1.7.0 CLASSPATH: .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; PAT ...