Question

In: Computer Science

Trace the execution of my_recursive_function(100) and my_recursive_function(32) for the following code snippet. [0.5 M] void my_recursive_function(int...

Trace the execution of my_recursive_function(100) and my_recursive_function(32) for the following code snippet. [0.5 M]
void my_recursive_function(int n) {
if(n == 0) {
printf("False");
return;
}
if(n == 1) {
printf("True");
return;
}
if(n%2==0)
my_recursive_function(n/2);
else {
printf("False");
return;
}
}
int main() {
my_recursive_function(n);
return 0;
}

Solutions

Expert Solution


Related Solutions

Question 31 Given the code snippet below, what prints? void fun(int *p) { int q =...
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); cout << *p; return 0; } Question 31 options: 10 20 compiler error Runtime error Question 32 A union’s members are exactly like the members of a Structure. Question 32 options: True False Question 33 Given the code below, what are the errors. #include <iostream> using namespace...
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
   private static void merge(int arr[], int l, int m, int r) {        //...
   private static void merge(int arr[], int l, int m, int r) {        // Find sizes of two subarrays to be merged        int n1 = m - l + 1;        int n2 = r - m;        /* Create temp arrays */        int L[] = new int[n1];        int R[] = new int[n2];        /* Copy data to temp arrays */        for (int i = 0; i...
why my code for mergesort always wrong ? void Merge(vector<int>& data, int p, int q, int...
why my code for mergesort always wrong ? void Merge(vector<int>& data, int p, int q, int r) { int n1 = q - p + 1; int n2 = r - q; vector<int>left(n1); vector<int>right(n2); for(int i = 0; i < n1; i++) { left[i] = data[p + i]; } for(int j = 0; j < n2; j++) { right[j] = data[q+j+1]; } int i = 0; int j = 0; for(int k = p; k <= r; k++) { if(left[i]...
Please explain this code line by line void printperm(int *A,int n,int rem,int j) {    if(n==1)...
Please explain this code line by line void printperm(int *A,int n,int rem,int j) {    if(n==1)       {        for(int k=0;k<j;k++)        cout<<A[k]<<" + ";        cout<<rem<<"\n";        return;       }     for(int i=0;i<=rem;i++)    {          if(i<=rem)          A[j]=i;          printperm(A,n-1,rem-i,j+1);    } }
void phase05(){ int n = atoi(next_input()); int m = atoi(next_input()); int t = (hash % 30)...
void phase05(){ int n = atoi(next_input()); int m = atoi(next_input()); int t = (hash % 30) + 21; int s = 0; while(n>1){ if(n & 1){ n = (n<<2) - n + 1; } else { n = n >> 1; } if(s == t && m == t){ return; } s++; } failure("Seems you forgatz the essence of Collatz"); } Hash value: 2002296385 what input values should n, m have in order for the function phase05 to work?
Trace the execution of quicksort on the following array, assuming that the first item in each...
Trace the execution of quicksort on the following array, assuming that the first item in each subarray is the pivot value. Show the values of first and last for each recursive call and the array elements after returning from each call. Also, show the value of pivot during each call and the value returned through pivIndex. How many times is sort called, and how many times is partition called? 55 50 10 40 80 90 60 100 70 80 20...
Make a detailed trace of the execution of the following program fragment, giving the contents of...
Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved. Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of AX, BX, CX, and DX are 789Ah, 0020h, 2000h, and 1234h respectively. SS SP TOS AX BX CX DX Initial contents 0990 0100 / 789A 0020 2000 1234 after PUSH AX after PUSH BX after PUSH CX...
1. Consider the following code: public class Widget implements Serializable { private int x; public void...
1. Consider the following code: public class Widget implements Serializable { private int x; public void setX( int d ) { x = d; } public int getX() { return x; } writeObject( Object o ) { o.writeInt(x); } } Which of the following statements is true? I. The Widget class is not serializable because no constructor is defined. II. The Widget class is not serializable because the implementation of writeObject() is not needed. III. The code will not compile...
Consider the following program written in C syntax: void swap(int a, int b) { int temp;...
Consider the following program written in C syntax: void swap(int a, int b) { int temp; temp = a; a = b; b = temp;} void main() { int value = 2, list[5] = {1, 3, 5, 7, 9}; swap(value, list[0]); swap(list[0], list[1]); swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three calls to swap? Passed by value Passed by reference Passed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT