Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this is the code that needs to be completed based on the picture below. it is in

ID: 3574709 • Letter: T

Question

this is the code that needs to be completed based on the picture below.

it is in c programming

#include

#include

#include

int recursiveFunction(int n);

int main(int argc, char **argv) {

if(argc != 2) {

fprintf(stderr, "Usage: %s n ", argv[0]);

exit(1);

}

int n = atoi(argv[1]);

time_t start, end;

start = time(NULL);

int result = recursiveFunction(n);

end = time(NULL);

int time = (end - start);

printf("f(%d) = %d ", n, result);

printf("Computation Time: %d seconds ", time);

return 0;

}

int recursiveFunction(int n) {

if(n == 0) {

return 2;

} else if(n == 1) {

return 2;

} else {

return recursiveFunction(n-1) + (recursiveFunction(n - 2) / 2);

}

}

The Jacobsthal sequence is very similar to the Fibonacci sequence in that it is defined by its two previous terms. The difference is that the second term is multiplied by two. J_n = {0 if n = 0; 1 if n = 1; J_n - 1 + 2J_n - 2 if n > 1. Write a recursive function to compute the n-th Jacobsthal number. Write a main function that reads in an integer n and outputs J_n. Test your program for n = 32, the largest Jacobsthal number expressible by a 32-bit signed 2-s complement integer. Answer the questions on your worksheet.

Explanation / Answer

#include<stdio.h>

#include<stdlib.h>

int recursiveFunction(int n);

int main(int argc, char **argv) {

if(argc != 2) {

fprintf(stderr, "Usage: %s n ", argv[0]);

exit(1);

}

int n = atoi(argv[1]);

time_t start, end;

start = time(NULL);

int result = recursiveFunction(n);

end = time(NULL);

int time = (end - start);

printf("f(%d) = %d ", n, result);

printf("Computation Time: %d seconds ", time);

return 0;

}

int recursiveFunction(int n) {

if(n == 0) {

return 2;

} else if(n == 1) {

return 2;

} else if(n == 1) {

return 2;

} else {

return recursiveFunction(n-1) + 2*(recursiveFunction(n - 2) );

}

}