. Determine what is calculated for n = 5:
unsigned int F(unsigned int n)
{
if(n == 0)
return 1;
return n ∗ F(n − 1);
}
Write an iterative version of the function in this problem
F(5) = 5 * 4 * 3 * 2 * 1 * 1 = 120 iterative version of the function is unsigned int F(unsigned int n){ unsigned int result = 1; while(n>0){ result *= n; n--; } return result; }
. Determine what is calculated for n = 5: unsigned int F(unsigned int n) { if(n...
Given the following recursive function: unsigned int mymod( unsigned int a, unsigned int b ) { if( a < b ) return a; return mymod( b - a, b ); } the function call mymod(5, 2) will Select one: a. execute infinitely and terminates with an error. b. execute until some if-condition matches. c. not compile, it will generate a compilation error. d. return the value: 1
What does this function return if it is called with n = 4? int f(int n) { if (n == 0) return 1; else return f(n-1) + 1; } Can you show the steps as well please?
Q5 (25pts) Consider the code: int foo(int N){ if (N <= 3) return 2; int res1 = 3*foo(N-4); int res2 = foo(N-2); return res1-res2; } a) (6 points) Write the recurrence formula for the time complexity of this function (including the base cases) for N>=0. You do NOT need to solve it. b) (5 points) Draw the tree that shows the function calls performed in order to compute foo(8) (the root will be foo(8) and it will have a child...
5.43 (10 pts) What does the following program do? #include <stdio.h> 3 unsigned int mystery Cuns igned int a, unsigned int b): // function prototype 5 int main(void) printf("%s". "Enter two positive integers: unsigned int x: I/ first integer unsigned int y: // second integer scanf("Su%u". &x, &y); "); 12 13 14 15 II Parameter b must be a positive integer 16 to prevent infinite recursion 7 unsigned int mystery Cuns igned int a, unsigned int b) 18 printf("The result...
What is the output of the following java function when called as f(1,25,25)? Int f(int a, int b, int n){ int mid =(a+b)/2; if ((mid*mid <=n) && (n< (mid+1)*(mid+1)) return mid; else If (mid*mid>n) return f(a,mid-1,n); else return f(mid+1,b,n); } B.) Is the following function tail-recursive? Acker(m,n){ if(m=0) n+1 else if(n=0) Acker(m-1,1) else Acker(m-1,Acker(m,n-1)) }
In C, thanks. #include <stdio.h> void set-flag (unsigned int* flag-holder , int flag-position); void unset-flag (unsigned int * flag-holder, int flag-position); int check-flag (unsigned int flag-holder , int flag-position); void display -32_flags (unsigned int flag-holder); int main(int argc, char* argv (1) unsigned int flag -holder = 0; set-flag (& flag-holder, 3); set-flag (& flag-holder, 16); set-flag (& flag-holder, 31); display-32-flags (flag-holder); unset-flag(& flag-holder , 31); unset-flag (& flag-holder, 3); set-flag (& flag-holder , 9); display-32-flags (flag-holder ); return 0; Write...
(5 pts) What is the ouput of the following function F, for the call int i = F(3)? int F(int n) { int result; if (n > 20) return 1; else { result = F(2*n) * 2; cout << result << " "; return result; } }
Write a C function named f such that … the prototype of function f is … unsigned long int f ( unsigned long int X, unsigned long int Y ) function f returns … the nonnegative integer Z such that X 2 + Y 2 = Z 2 if such a nonnegative integer Z exists zero if there is no nonnegative integer Z such that X 2 + Y 2 = Z 2 Example 1 If X = 3 and Y = 4 ...
11 Write a function with the following prototype: /* Determine whether arguments can be added without overflow */ int uadd_ok (unsigned x, unsigned y); This function should return 1 if arguments x and y can be added without causing overflow 11 Write a function with the following prototype: /* Determine whether arguments can be added without overflow */ int uadd_ok (unsigned x, unsigned y); This function should return 1 if arguments x and y can be added without causing overflow
C programming KAM5 Write a function unsigned long long int factorial(int num) to compute the factorial of a number. The factorial of a number is given by n! = 1*2* ... *n So 1! = 1, 2! = 1*2, 3! = 1*2*3 ... For example: Test Result printf("%llu\n", factorial(5)); 120 printf("%lu\n", factorial(20)); 2432902008176640000