Saturday 19 March 2016

Fibonacci Roots


The first two terms in the Fibonacci sequence are 0 and 1, respectively, and each subsequent term is the sum of the previous two. Using this definition to calculate the first several terms in the sequence, we get

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Let us define the Fibonacci roots of a positive integer n to be the two smallest consecutive Fibonacci numbers whose sum is greater than or equal to n.

Input Format: 
Input consists of a single integer which corresponds to n.
Assumption: 
Assume that n is less than or equal to 2000.
Output Format: 
Output consists of integers, separated by a space.
Sample Input 1 : 
31
Sample Output 1: 
13 21
Sample Input 2 : 
89
Sample Output 2: 
34 55

Code:
  #include<stdio.h>
int main(){
  int a=0,b=1,c=0,n;
  scanf("%d",&n);
  while(1){
    c=a+b;
    if(c>=n)
      goto END;
    a=b;
    b=c;
  }
  END: printf("%d %d",a,b);
  return 0;
}

2 comments:




  1. Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am
    on the look for such information.


    Function Point Estimation Training in Chennai

    ReplyDelete
  2. The CBSE will allow the applicants to download their Admit Card NEET from the Boards official website along with the format for affixing of postcard size photograph.

    ReplyDelete