首页 > 代码库 > scip习题(1) scheme和c实现的对比
scip习题(1) scheme和c实现的对比
习题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(1,2,3);
return 0;
}
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实现的对比
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。