Fibonacci Numbers
Limits
1s, 512 MB
Given an integer N, print the Nth Fibonacci number.
A Fibonacci series is a series of numbers in which each number is the sum of the two numbers proceeding it. For this problem, you can assume that the first two numbers in the series are 1 and 1.
Below you can see the first few numbers of the series:
A Fibonacci series is a series of numbers in which each number is the sum of the two numbers proceeding it. For this problem, you can assume that the first two numbers in the series are 1 and 1.
Below you can see the first few numbers of the series:
1, 1, 2, 3, 5, 8, ...
Input
The input will contain an integer N (0 < N < 50).
Output
Print the Nth Fibonacci number.
#include <stdio.h>
int main()
{
int n[51],i,num;
scanf("%d", &num);
n[0]=1;
n[1]=1;
for(i=2; i<=50; i++)
{
n[i]=n[i-1]+n[i-2];
}
printf("%d\n",n[num-1]);
}