Question: In C coding language, not C + + , please complete the following 2 code files wherever a / / TODO is marked. The

In C coding language, not C++, please complete the following 2 code files wherever a "// TODO" is marked. The instructions are also attached for reference. A picture of another file, jacobsthal.c, is also attached, but only for reference and not to be completed.
Code file #1(jacobsthalMemoization.c):
#include
#include
#include
/**
* Computes the n-th Jacobsthal number using an iterative
* method
*/
long long jacobsthalIterative(int n);
//TODO: place your prototype and documentation here
//Hint: it should return a long long (integers)
//it should take a cache (array) of long longs as well
/**
* This program computes the n-th Jacobsthal number using recursion.
* It also reports how long the program takes to execute.
*
*/
int main(int argc, char **argv){
if (argc !=2){
fprintf(stderr, "Usage: %s n
", argv[0]);
exit(1);
}
int n = atoi(argv[1]);
//TODO: set up our table/cache which is of size n +1 since we
//compute values from J(0) to J(n) inclusive
//TODO: initialize the table values
//1. take care of the base cases
//2. set all other values to a flag value (-1) to indicate
// the value has not yet been computed and cached
time_t start, end;
long long iterativeResult = jacobsthalIterative(n);
start = time(NULL);
//TODO: call your function here
end = time(NULL);
int time =(end - start);
printf("Iterative: Jacobsthal(%d)=%lld
", n, iterativeResult);
printf("Memoization: Jacobsthal(%d)=%lld
", n, memoizationResult);
printf("Total Computation Time: %d seconds
", time);
return 0;
}
//TODO: write your memoization-based Jacobsthal function here
long long jacobsthalIterative(int n){
if(n =1){
return n;
}
long long prev =0;
long long curr =1;
for(int i=2; i=n; i++){
long long t =2* prev + curr;
prev = curr;
curr = t;
}
return curr;
}
Code file #2(palindrome.c):
/**
* A program to compute whether or not a given
* string is a palindrome (the same backwards as
* forwards).
*/
#include
#include
#include
/**
* This function should return true if the given (sub)string is
* a palindrome. The function should be recursive.
*/
int isPalindrome(const char *str, int leftIndex, int rightIndex);
int main(int argc, char **argv){
if (argc !=2){
printf("Usage: isPalindrome word
");
exit(1);
}
int isPal = isPalindrome(argv[1],0, strlen(argv[1])-1);
if (isPal){
printf("%s is a palindrome!
", argv[1]);
} else {
printf("%s is NOT a palindrome!
", argv[1]);
}
return 0;
}
int isPalindrome(const char *str, int leftIndex, int rightIndex){
// TODO: implement this function as specified
}
In C coding language, not C + + , please complete

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!