Scip Exercises (1) Comparison of scheme and C implementations

Source: Internet
Author: User

Exercise 1.3

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

Scheme implementation

( 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)) c19/>

C Language Implementation

//some exercises of SCIP (computer program construction and interpretation) are implemented in C language. Compare and further understand the functional thinking of scheme//Define A procedure thats three numbers as argument and return the sum of the square of the large//numbers.//C Language Implementation#include"stdafx.h"#include<iostream>using namespacestd;intSquareintx);intSum_of_square (intAintb);intBigger_num (intAintb);intTwo_more_bigger_sum_of_square (intAintBintc);intSmaller_num (intAintb);//Check the CodeintMain () {cout<<two_more_bigger_sum_of_square (1,2,3); return 0;}intSquareintx) {returnx*x;}//Retun The sum of the num of squareintSum_of_square (intAintb) {returnSquare (a) +Square (b);}//return the bigger numintBigger_num (intAintb) {if(A >b)returnA; Else        returnb;}//takes the both Num as agrument and return the smaller numintSmaller_num (intAintb) {//return the bigger num    if(A >b)returnb; Else        returnA;}

Scip Exercises (1) Comparison of scheme and C implementations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.