Showing posts sorted by relevance for query fibonacci. Sort by date Show all posts
Showing posts sorted by relevance for query fibonacci. Sort by date Show all posts

Saturday, 11 March 2017

C Program to Print Fibonacci Series



In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:

1,1,2,3,5,8,13,21,34,55,89,144...
Often, especially in modern usage, the sequence is extended by one more initial term:

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



By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.

In mathematical terms, the sequence F(n) of Fibonacci numbers is defined by the recurrence relation:

F(n) = F(n-1) + F(n-2)

It defines that the the nth term of the sequence is sum of two previous terms.

F(4) = F(3) + F(2) = 1 + 1 = 2 

Here is a non-recursive  code of C Program to print first 'n' terms of Fibonacci Series

#include<stdio.h>
void main()
{
int a=-1,b=1,n,i,c;
printf("\n************************Fibonacci Series****************************\n");
printf("Enter number of terms you want to print\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
printf("%d\t",c);
}
}

Here is a recursive  version code of C Program to print first 'n' terms of Fibonacci Series

#include<stdio.h>
int fib(int n)
{
if(n==1)
return 0;
else if(n==2)
return 1;
else
return fib(n-1)+fib(n-2);

}
void main()
{
int n,s,i=1;
clrscr();
printf("\n************************Fibonacci Series****************************\n");
printf("Enter number of terms you want to print\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s=fib(i);
printf("%d\t",s);
}
}
Output::



C Program to print first 'n' terms of Fibonacci Series

non-recursive code of C Program to print first 'n' terms of Fibonacci Series
Fibonacci series in c
recursive version code of C Program to print first 'n' terms of Fibonacci Series
c program for Fibonacci series without and with recursion.
best program to print fibonacci series


Fibonacci Series algorithm ,Fibonacci Series non-recursive algorithm ,Fibonacci Series iterative algrothim ,Fibonacci Series recursive program in c,

Sunday, 23 January 2022

NET December 2021 Computer Science Solved Paper 2 Question 1

 Q: 1 Let us assume a person climbing the stairs can take one stair or two stairs at a time. How many ways can this person climb a flight of eight stairs?

(a) 21

(b) 24

(c) 31

(d) 34

Answer : d


Solution:

First Method :


In this case answer would be 9th Fibonacci number as number of stairs are 8 so answer is fib(9) = 34.
If number of stairs = n then total ways will be fib(n+1).
Second Method :

Here, we have to use the concept of combination to find the number of ways in which a person can walk up a stairway which has 8 steps. So, we have to make
pairs of the combination of 1 and 2 steps and then by using the concept of the combination we will get the number of ways a person can walk up a stairway of 8 steps.



It is given that there are 8 steps of the stairway and he can take only 1 or 2 steps up the
stairs at a time.


   No. of Step 1               No. of Step 2               Total Ways
   8                                        0                                    1               
   6                                        1                                  (7!)/(6!)(1!) = 7
   4                                        2                                  (6!)/(4!)(2!) = 15
   2                                        3                                  (5!)/(2!)(3!) = 10
   0                                        4                                     1

Adding all we get 1+7+15+10+1= 34
So, 34 is right answer which is also 9th Fibonacci Number.


#NTA #NET #NETDECEMBER2021 Discrete Mathematics Combination