Question

write in C language

In = { 3.3 The Jacobsthal Function The Jacobsthal sequence is very similar to the Fibonacci sequence in that it is defined by

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you will feel any problem with the solution, then feel free to ask it in comments.

Happy HomeworkLibing

Maximum Jacobii number by 32 bit 2's complement number is 1431655765 for n=32

HomeworkLib70.c

#include<stdio.h>

int J(int n) {
    if (n == 0)
        return 0;
    else if (n == 1)
        return 1;
    else {
        return J(n-1) + 2*J(n-2);
    }
}

int main() {
    int n;
    printf("Enter n: ");
    scanf("%d", &n);
    printf("Jacobsthal(%d) = %d\n", n, J(n));
    return 0;
}

OUTPUT

(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ gcc HomeworkLib70.c
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 1
Jacobsthal(1) = 1
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 2
Jacobsthal(2) = 1
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 4
Jacobsthal(4) = 5
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 8
Jacobsthal(8) = 85
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 16
Jacobsthal(16) = 21845
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 32
Jacobsthal(32) = 1431655765
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 33
Jacobsthal(33) = -1431655765
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 34
Jacobsthal(34) = 1431655765
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ ./a.out
Enter n: 32
Jacobsthal(32) = 1431655765
(base) avianjjai@avianjjai-Vostro-3578:~/Desktop/Chegg$ 
Add a comment
Know the answer?
Add Answer to:
write in C language In = { 3.3 The Jacobsthal Function The Jacobsthal sequence is very...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence....

    Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence. Your program should prompt for an integer input n from the user. The program should call a recursive function to compute the nth fibonacci number. Your program must follow programming convention. You should submit program and screenshot of output in a single word/pdf file. You should use following recursive definition of fibonacci function: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) +fib(n-2)

  • Below you will find a recursive function that computes a Fibonacci sequence (Links to an external...

    Below you will find a recursive function that computes a Fibonacci sequence (Links to an external site.).   # Python program to display the Fibonacci sequence up to n-th term using recursive functions def recur_fibo(n): """Recursive function to print Fibonacci sequence""" if n <= 1: return n else: return(recur_fibo(n-1) + recur_fibo(n-2)) # Change this value for a different result nterms = 10 # uncomment to take input from the user #nterms = int(input("How many terms? ")) # check if the number...

  • Write the code in java programming language To get some practice with recursion. You can do...

    Write the code in java programming language To get some practice with recursion. You can do all this in one driver program. Write a recursive method to compute the result of the Fibonacci sequence: Fibonacci(N) = Fibonacci(N -1) + Fibonacci(N-2) N == 0 is 0 N == 1 is 1 Testing: Display the result for Fibonacci(N) and the number of function calls for N = 2, 5 and 10.

  • write a C program!! Q2 and Q3 Write the following functioned int search(int a[], int n,...

    write a C program!! Q2 and Q3 Write the following functioned int search(int a[], int n, int key, int **loc); a is an array to be searched, n is the number of elements in the array, key is the search key, and loc is a pointer to the first location of the search key in array a (if found) or NULL otherwise. The function returns 1 if key is found in a, and returns 0 otherwise. Write a main() and...

  • Write an ARM assembly language subroutine (named nfibo) to calculate and return the n-th Fibonacci number....

    Write an ARM assembly language subroutine (named nfibo) to calculate and return the n-th Fibonacci number. Fibonacci numbers (or a Fibonacci sequence) are a series of numbers with a property that the next number in the series is a sum of previous two numbers. Starting the series from 0, 1 as the first two numbers we have 0, 1, (0 + 1) = 1, (1 + 1) = 2, (1 + 2) = 3, (2 + 3) = 5, (3...

  • in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5,...

    in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5, 8, 13, 21, 34, 55, 89.. 1 See the pattern? Each element in the series is the sum of the preceding two items. There is a recursive formula for calculating the nth number of the sequence (the oth number if Fib(0)-0): 8 Fib(N)-/N, if N 0 or 1 ifN> 1 Fib(N-2) Fib(N-1), a. b. c. Write a recursive version of the function Fibonacci. Write...

  • Question 3 Program Language C++ Problem 3 Fibonacci Numbers 10 points Fibonacci numbers are a sequence...

    Question 3 Program Language C++ Problem 3 Fibonacci Numbers 10 points Fibonacci numbers are a sequence of numbers where each number is represented by the sum of the two preceding numbers, starting with 0 and 1: 0, 1, 1, 2, 3, 5, 8, etc Write a program that repeatedly prompts the user for a positive integer and prints out whether or not that integer is a Fibonacci number. The program terminates when-I is entered. Create a method with the following...

  • c++ language Write a program that contains the following functions, i. A function isVowel that takes...

    c++ language Write a program that contains the following functions, i. A function isVowel that takes in a character and returns true if it is a vowel and false otherwise ii. A function that request from the user to enter in a sequence of characters, and outputs the number of vowels entered. (Use Function in a) to assist you, a sentinel value can be used to specify the end of the user input iii. A function that reads 3 test...

  • 1. Write an iterative C++ function that inputs a nonnegative integer n and returns the nth...

    1. Write an iterative C++ function that inputs a nonnegative integer n and returns the nth Fibonacci number. 2. Write a recursive C++ function that inputs a nonnegative integer n and returns the nth Fibonacci number.

  • ** C++ LANGUAGE ** Write a function that will implement each Fibonacci number with the help...

    ** C++ LANGUAGE ** Write a function that will implement each Fibonacci number with the help of an integer array of size 100 (elements of this array will be digits of the Fibonacci number). When the function is called to find , it will calculate all Fibonacci numbers from to using the basic formula . To add two Fibonacci numbers, the function will add elements of two arrays corresponding to and and store their sums in the array corresponding to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT