1#include <stdio.h>
2int main() {
3 int i, n, t1 = 0, t2 = 1, nextTerm;
4 printf("Enter the number of terms: ");
5 scanf("%d", &n);
6 printf("Fibonacci Series: ");
7
8 for (i = 1; i <= n; ++i) {
9 printf("%d, ", t1);
10 nextTerm = t1 + t2;
11 t1 = t2;
12 t2 = nextTerm;
13 }
14
15 return 0;
16}
17
1#include <stdio.h>
2#include <stdlib.h>
3
4int main() {
5 long int a = 1,b = 2, c, d, cont = 0;
6 double e, f;
7
8 printf("Fibonacci fino a: ");
9 scanf("%ld", &c);
10
11 while(b < c)
12 {
13 cont ++;
14 printf("\n%ld", b);
15 d = a;
16 a = b;
17 b = b + d;
18 }
19
20 f = (double)b / (double)a;
21
22 e = (double)cont / (double)c * (double)100;
23
24 printf("\n\nOttenuto: %lf\nPercentuale: %lf\n\n\n", f, e);
25
26 system("pause");
27}
1
2 fib(5)
3 /
4 fib(4) fib(3)
5 / /
6 fib(3) fib(2) fib(2) fib(1)
7 / / /
8 fib(2) fib(1) fib(1) fib(0) fib(1) fib(0)
9 /
10fib(1) fib(0)
11