scip习题 scheme和c实现的对比

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scip习题 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习题 scheme和c实现的对比的主要内容,如果未能解决你的问题,请参考以下文章

SCIP习题 1.9

SCIP习题 1.10

SCIP习题 1.4

SCIP习题 1.1

SCIP习题 1.21(寻找最小因子)

scip 练习2.20