zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    js-html音乐播放
    CSS-实现倒影效果box-reflect
    html-屏蔽按键盘空格键是滚动条向下滚动
    html-禁用右键、键盘F12、网页上选取内容、复制、粘贴
    js-回调函数
    man bash 关于shell的应有尽有 语法、快捷键...
    source vs export AND ctrl d vs ctrl z
    技术----阳春
    限流 降级
    linux TOP
  • 原文地址:https://www.cnblogs.com/everydaykeepgoing/p/6128320.html
Copyright © 2011-2022 走看看