Question

Question 32 (Programming) The Fibonacci sequence of number is defined as: In this question we examine...

Question 32 (Programming)

The Fibonacci sequence of number is defined as: In this question we examine a property of this sequence.

a) Write a C function definition with header int fib(int [ ] a, int n) which generates an array, a of the first n Fibonacci numbers.

(Hint: You do not have to write this recursively. You just have to generate each array entry from the previous two entries.)

b) Two numbers are said to be coprime if they have no divisors in common. (For example 16 and 81 are coprime numbers). Write a C function definition with header int coprime(int a, int b) which returns 1 (true) if a and b are coprime and 0 (false) otherwise.

c) A property of Fibonacci numbers is that any two consecutive numbers in the sequence are coprime. Write a C program to verify this property. Your program should read an input value N, generate an array of the first N Fibonacci numbers, and then test them to verify that each pair of consecutive numbers is coprime. It should return a message indicating “Success” if that is the case or “Fail” if there is a pair of consecutive numbers which is not coprime.

Question 33 (Programming)

Write a Matlab function definition that takes a parameter n and returns an vector consisting of the first n Fibonacci numbers. (See the previous question for the definition of Fibonacci numbers.

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

C Program for fibnocci series and coprimes

--------------------------------------------------------------------------------------

#include<stdio.h>

#include<conio.h>

int coprime(int a,int b);

int main()

{

int a=0,b=1,n,i,first=0,second=0,c=0,flag=0;

int fib[100];

printff("Enter number of elements");

scanf("%d",&n);

fib[0]=0;

fib[1]=1;

for(i=2;i<n;i++)

{

c=a+b;

fib[i]=c;

a=b;

b=c;

}

for(i=0;i<(n-1);i++)

{

first=fib[i];

second=fib[i+1]

flag=coprime(first,second);

if(flag==1)

printf("Success");

else

printf("Fail");

}

}

int coprime(int a,int b)

{

int temp;

while(1)

{

temp=a%b;

if(temp==0)

return b;

a=b;

b=temp;

}

}

Matlab program for fibonacci series

------------------------------------------------------------------------------------------------

create a function named as fibonacci:

function[result]=fibonacci(i);

if n==0||n==1
    result = n;

else
    result = fibonacci(n-2)+fibonacci(n-1);
end
end

Write the code to your command window:

-----------------

for n = 0:10
   fprintf('Fibonacci(%d)= %d\n', n, fibonacci(n));
end

Add a comment
Know the answer?
Add Answer to:
Question 32 (Programming) The Fibonacci sequence of number is defined as: In this question we examine...
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)

  • use Java please. The Fibonacci Sequence Given the initial Fibonacci numbers 0 and 1, we can...

    use Java please. The Fibonacci Sequence Given the initial Fibonacci numbers 0 and 1, we can generate the next number by adding the two previous Fibonacci numbers together. For this sequence, you will be asked to take an input, denoting how many Fibonacci numbers you want to generate. Call this input upperFibLimit. The longest Fib sequence you should generate is 40 and the shortest you should generate is 1. So,1<upperFibLimit<40 The rule is simple given f(0) 0, f(1) 1 ....

  • C# - Using Visual Studio 2017/2019 The Fibonacci sequence is a numerical sequence that follows a...

    C# - Using Visual Studio 2017/2019 The Fibonacci sequence is a numerical sequence that follows a simple pattern: 1,1, 2, 3, 5, 8, 13, 21, 34, 55, By definition, the first two numbers are 1 and 1, and each subsequent number is the sum of the previous two. For your program, you will ask the user to enter a number, n, and then calculate and display the values of the Fibonacci sequence to the nth position. ==sample output== Enter an...

  • In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.......

    In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.... In mathematical notation the sequence Fn of Fibonacci number is defined by the following recurrence relation: Fn=Fn-1+Fn-2 With the initial values of F0=0 and F1=1. Thus, the next number in the series is the sum of the previous two numbers. Write a program that asks the user for a positive integer N and generate the Nth Fibonacci number. Your main function should handle user...

  • Fibonacci function Fib(n) is given below. Fib(n)= Fib(n-1) + Fib(n-2) for n > 1 Fib(n)= 1...

    Fibonacci function Fib(n) is given below. Fib(n)= Fib(n-1) + Fib(n-2) for n > 1 Fib(n)= 1 for n=1 Fib(n)= 0 for n=0 Using following initialization unsigned int *Fib = new unsigned int[30]; and function prototypes void push(int n) unsigned int pop( ) insert first 30 Fibonacci numbers into dynamic array Fib and then pop them to print out first 30 numbers in descending order. The output of your program should be 514229, 317811, 196418, ......, 1, 1, 0

  • Question 2: (25marks) By definition, the first and second of the modified-Fibonacci numbers are 1 and 2 (e.g. h(0)=...

    Question 2: (25marks) By definition, the first and second of the modified-Fibonacci numbers are 1 and 2 (e.g. h(0)=1 and h(1)-2), and each subsequent number is the sum of the previous two. a. Write the closed form of the causal Fibonacci function h(n)? b. Write ten Fibonacci number, h(n) for n=0, 1, ,9 described by the above definition? c. Calculate the 4-FFT of the sequence in (b). d. Finally, compute the 4-point IDFT of the result and verify that you...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,...

    The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … The next number is found by adding up the two numbers before it. For example, the 2 is found by adding the two numbers before it (1+1). The 3 is found by adding the two numbers before it (1+2). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called...

  • A Fibonacci sequence is a series of numbers where the next number in the series is...

    A Fibonacci sequence is a series of numbers where the next number in the series is the sum of the previous two numbers. The sequence starts with the numbers 0 and 1. Here are the first ten numbers of the Fibonacci sequence:             0 1 1 2 3 5 8 13 21 34 Write a Java program to print out the first fifteen numbers of the Fibonacci sequence using a loop. You will need three variables previous, current, and next...

  • om me insert e Search - Assignment - Word Design Layout References Mailings Review Lucida Sans...

    om me insert e Search - Assignment - Word Design Layout References Mailings Review Lucida Sans Typ 11 - A A A A - BIU XX A.D.A. View ру mat Painter rd CIT 111 Help! 21 - - 19. ABCD AaBbcDc AaB 1 Normal TNo Spac... Head Paragraph PROGRAMS SPRING 2020 8.3 points Write a method that determines if a positive integer is an abundant number. A number is abundanti the sum of its proper divisors (a divisor that isn't...

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