Define procedure to input integers and returns the average, C/C++ Programming

The procedure +, * and list take arbitrary numbers of arguments. One way to define such a procedure is to use define with dotted-tail notation. In a procedure definition, a parameter list that has a dot before the last parameter name indicates that, when the procedure is called, the initial parameters (if any) will have as values the initial arguments, as usual, but the final parameter's value will be a list of any remaining arguments. For instance, give the definition:

(define (f x y . z) )

the procedure f can be called with two or more arguments. If we evaluate

(f 1 2 3 4 5 6)

then in the body of f, x will be 1, y will be 2, and z will be the list (3 4 5 6).

Given the definition:

(define (g . w) )

the procedure g can be called with 0 or more arguments. If we evaluate

(g 1 2 3 4 5 6)

then in the body of g, w will be the list ( 1 2 3 4 5 6).

(a) Use this notation to write a procedure average that takes one or more integers and returns the average. For example:

(average 1 2 3 4 5 6 7) => 4
(average 2) => 2

(b) Write a procedure called pipeline that accepts a variable number of arguments that are procedures and returns the composition of those procedures. This is called pipeline processing. You may assume that all procedures in the pipeline accept a single argument. For example:
(define square-cubed (pipeline square square square))
; is equivalent to:
(define square-cubed (lambda (x) (square (square (square x)))))
(square-cubed 2) => 256

(c) Using your definition for pipeline from (b), write procedures for cdar, cddar and cdadr.

Posted Date: 3/25/2013 1:10:19 AM | Location : United States







Related Discussions:- Define procedure to input integers and returns the average, Assignment Help, Ask Question on Define procedure to input integers and returns the average, Get Answer, Expert's Help, Define procedure to input integers and returns the average Discussions

Write discussion on Define procedure to input integers and returns the average
Your posts are moderated
Related Questions
Question : (a) Define the following Object-Oriented terms: (i) Encapsulation (ii) Inheritance (iii) Abstraction (iv) Polymorphism. (b) What are objects in Lingo progra


Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

C Program for FUNCTION OF FIND THE FACTORIAL float factorial(float); void main() {           float i=0,c=0;           clrscr();           printf("ENTER THE DIGI

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw

Write a Program that illustrate Command Line Parameters? main(int argc, char *argv[]) { int i; for(i = 0; i printf("arg %d: %s\n", i, argv[i]); return 0; }

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Within software languages we have the ability to store information in mail boxes i.e. memory slots which are given names to represent the box. The naming rules are governed by the

The new and delete operators The C language has explained library functions- malloc() and free() for dynamic allocation and de-allocation of memory. C++ gives yet another appro

Define the C Preprocessor? Preprocessor' is a translation stage that is applied to your source code before the compiler proper gets its hands on it usually the preprocessor per