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.
Below is is a scheme function. For your answer, write a comment for this piece of...
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 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 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 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...
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.
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...
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...
As described in the function prototype comment, this function takes two arguments, a single-dimension character array of scores (E/M/R/N) and an integer designating the size of the array, and returns an integer indicating the next homework number (zero-based) the student should submit. If any score is 'R' or 'N', then the index of the first such score is returned. Next, if any score is an 'M', then the index of the first such score is returned. Finally, if all the...
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...
Write a C++ program that will test function described below that use pointers and dynamic memory allocation. Functions: You will write the function described below. Then you will call them from the main function, to demonstrate their correctness. concat_array: takes two int arrays and the arrays' sizes as arguments (that's 4 arguments). It should create a new array big enough to store both arrays. Then it should copy the contents of the first array to the new array, and then...