what does the if -elseif statement is doing explain the meaning of this ?

0 votes
asked Sep 4 by if -elseif
#include<stdio.h>
int fibonacci_series(int);
int main()
{
   int count, c = 0, i;
   printf("Enter number of terms:");
   scanf("%d",&count);
 
   printf("\nFibonacci series:\n");
   for ( i = 1 ; i <= count ; i++ )
   {
      printf("%d\n", fibonacci_series(c));
      c++; 
   }
 
   return 0;
}
int fibonacci_series(int num)
{
   if ( num == 0 )                                      //explain this
     return 0;                              
   else if ( num == 1 )                                  //explain this
     return 1;
   else
     return ( fibonacci_series(num-1) + fibonacci_series(num-2) );
}

2 Answers

0 votes
answered Sep 12 by (220 points)
Well to understand you have to understand that the first two numbers in the fibonacci series are 0 and 1, you need those numbers to begin the sequence, every sequence starts somewhere, this return 0; and return 1; literally gives you the integers 0 and 1 for you to get the other numbers, with those two numbers you are capable of getting the third number in the sequence 0+1 = 1, with that you can get the fourth one 1+1 = 2 and so on, but without knowing they start at 0 or 1, the result is undefined
0 votes
answered Nov 7 by (1,070 points)
elfi means we can able to use both conditions at a time

fibonacci series:

a=int(input('enter the number upto u want: '))
first=0
second=1
for i in range(a):
    print(first)
    temp=first
    first=second
    second=temp+second

output

enter the number upto u want: 10
0
1
1
2
3
5
8
13
21
34
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...