Write a program to print Fibonacci series using recursion?
Output:
1: #include <stdio.h>
2: void fibo(int,int,int);
3: void main(void)
4: {
5: int x,y,c = 10;
6: x = 0;
7: y = 1;
8: printf("1 ");
9: fibo(x,y,c);
10: }
11: void fibo(int x,int y,int c)
12: {
13: int z;
14: if (c < 1)
15: return;
16: else
17: {
18: z = x + y;
19: printf("%d ",z);
20: fibo(y,z,c - 1);
21: }
22: }
Output:
1 1 2 3 5 8 13 21 34 55 89
No comments:
Post a Comment