Question

Below is is a scheme function. For your answer, write a comment for this piece of code in valid scheme syntax. (define (facto
0 1
Add a comment Improve this question Transcribed image text
Answer #1

The solution of the given problem is below:

here the code given is a scheme function for factorial . in scheme programming comments starts with a semocolon.

; the input n is a  number whose factorial is to be determined.

; let the input is 5 then above program work like this.

; since 5>0 so (*5 (factorial(5-1)))))

; again factorial will be called with n=4 so   (*4(factorial(4-1)))))

; (*3(factorial(3-1)))))

; (*2(factorial(2-1)))))

; (*1(factorial(1-1)))))

; factorial(0) will return 1 in this way it is calculated.

The ans of 2nd part is option 4.

generally comments are useless because compiler ignores it while compiling, but some times we need to add comment in order to tell that what our program does and its functions.

Plaese upvote in case of any query comment me.

Add a comment
Know the answer?
Add Answer to:
Below is is a scheme function. For your answer, write a comment for this piece of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1) Describe in your own words the fundamental concept behind declarative programming paradigm 2) Explain what...

    1) Describe in your own words the fundamental concept behind declarative programming paradigm 2) Explain what is happening below. Why are these results looking like this? Describe why it is happening in your own words. >(-10.2 10) 0.1999999999999993 >(-1.2 1) 0.1999999999999996 >(-1.4 1) 0.3999999999999999 >(-2.2 1) 1 .2000000000000002 3)Below is a scheme function. for your answer, write a comment for this piece of code in valid scheme syntax (define( factorial n) if(=n 0) 1 (*n(factorial(-n 1))))) The elements to include...

  • QUESTION 1 How can you implement iteration (such as checking if there are any even elements...

    QUESTION 1 How can you implement iteration (such as checking if there are any even elements in a linked list) in a purely functional language, when there's no loop variable concept? O Recursion O Declaring type signatures O Writing out clear, concise comments Find a dragon to help you QUESTION 2 Explain what is happening below. Why are these results looking like this? Describe why it is happening in your own words. >(-10.2 10) 0.1999999999999993 >(-1.2.1) 0.19999999999999996 >(-1.41) 0.3999999999999999 >(-2.2...

  • Write programs for the Ackerman function shown below in C and in Scheme (Racket). Functionality and...

    Write programs for the Ackerman function shown below in C and in Scheme (Racket). Functionality and Documentation is critical in these programs. Be sure your code is your own. If you get outside help, you will receive a zero for this exam. When you submit the programs, upload the c code and scheme code in separate files. The Ackermann function is defined recursively for two non-negative integers’ s and t as follows. A(s, t) = {(t+1,@A(s-1,1),@A(s-1,A(s,t-1)),)┤ ■(if s=0@ if s>0...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solu...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solutions. Instructions 1. Read instructions carefully! 2. Use C++ syntax only, C syntax will not be accepted. 3. Always use braces to define blocks. 4. Indent all lines within a block. Each block requires one more tab. 5. Organize your code well with proper formatting and a single...

  • Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of...

    Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of up to 100 digits (plus a sign). The calculator has a simple user interface, and 10 \variables" (n0, n1, ..., n9) into which hexadecimal integers can be stored. For example a session with your calculator might look like: mac: ./assmt1 > n0=0x2147483647 > n0+0x3 > n0? 0x214748364A > n1=0x1000000000000000000 > n1+n0 > n1? 0x100000000214748364A > n0? 0x214748364A > exit mac: Note: \mac: " is...

  • Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2...

    Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2 is equal to the sum of the first n odd numbers. For example, 16 = 4^2 = 7 + 5 + 3 + 1. Write a function that takes as input a natural number, n, and that returns the square of its input by adding the first n odd numbers. Your code may not contain delayed operations and must use accumulative recursion.

  • c++ page 2 ]. Write a C++ program that uses a recursive function to compute factorial...

    c++ page 2 ]. Write a C++ program that uses a recursive function to compute factorial (n!) Include comments in your code. dawoe llustrate with a ]. [extra credit] What are function or class "templates" in C++ ? ] Provide (short!) C++ code fragments which demonstrate how to write and re files. your code fragment should include preprocessor directive(s), all needed I/O declarations, and illustrative code for writing and reading data.eb ert benistno geami 10]. Write C++ code to sort...

  • I need help making my array into a function that can called by the main function...

    I need help making my array into a function that can called by the main function using my program. This is C programming int prime (int x) { int i; i = 2; while (i < x) { if (x % i == 0) return 0; i++; } return 1; } int main (void){ int n; scanf ("%d", &n); if (n < 1) { printf ("Error: at least one data value must be provided.\n"); return 1; } int a[n]; int...

  • 1. Specification Write a C program to implement a simple calculator that accepts input in the...

    1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...

  • Overview: In this course, you will be responsible for completing a number of programming-based assignments by...

    Overview: In this course, you will be responsible for completing a number of programming-based assignments by filling in the missing pieces of code. Learning to program in C++ requires developing an understanding of general programming concepts and learning the syntax of the C++ programming language. These exercises will build on each other and help you cultivate you programming knowledge. It is recommended that students do not limit their practice to just that which is graded. The more you write your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT