Before looking into the program to print Fibonacci numbers, let us look into what really it is.  Fibonacci numbers are a sequence of numbers known as a Fibonacci sequence which is characterized by the fact that ‘every number after the first two is the sum of the two preceding ones’ as shown below:

1, 1, 2, 3, 5, 8, 13, 21, …

From the sequence given above, we can see that there exists a recurrence relation as:

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

Let us use this relation to print the Fibonacci numbers, using a recursive method.

```.wp-block-code {
border: 0;
}

.wp-block-code > div {
overflow: auto;
}

.shcb-language {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
position: absolute;
width: 1px;
word-wrap: normal;
word-break: normal;
}

.hljs {
box-sizing: border-box;
}

.hljs.shcb-code-table {
display: table;
width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
color: inherit;
display: table-row;
width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
white-space: pre;
}

.wp-block-code code.hljs.shcb-wrap-lines {
white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
border-spacing: 0;
counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
}

.hljs.shcb-line-numbers .shcb-loc::before {
border-right: 1px solid #ddd;
content: counter(line);
display: table-cell;
text-align: right;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: 1%;
}
```#include<stdio.h>
int FIB(int);
main()
{
int n, i, c=0;
printf("\nEnter the number of terms:");
scanf("%d", &amp;n);
for(i=0; i&lt;n; i++)
{
printf("%d ", FIB(i));
c++;
}
return 0;
}
int FIB(int x)
{
if(x==0)
return 0;
else if(x==1)
return 1;
else
return(FIB(x-1)+FIB(x-2));
}
```Code language: PHP (php)```
Scroll to Top