1#include<stdio.h>
2
3void fibonacciSeries (int range);
4
5void main()
6{
7 int range;
8
9 printf("Enter range: ");
10 scanf("%d", &range);
11
12 printf("\nThe Fibonacci series is: \n");
13
14 fibonacciSeries(range);
15
16}
17
18void fibonacciSeries(int range)
19{
20 int a=0, b=1, temp;
21
22 while (a<=range)
23 {
24 printf("%d\t", a);
25 temp = a+b;
26 a = b;
27 b = temp;
28 }
29
30}
31
1int main()
2{
3 int n1=0,n2=1,n3,i,number;
4 printf("Enter the number of elements:");
5 scanf("%d",&number);
6 printf("\n%d %d",n1,n2);//printing 0 and 1
7 for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed
8 {
9 n3=n1+n2;
10 printf(" %d",n3);
11 n1=n2;
12 n2=n3;
13 }
14 return 0;
15 }
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>
2int main() {
3 int t1 = 0, t2 = 1, nextTerm = 0, n;
4 printf("Enter a positive number: ");
5 scanf("%d", &n);
6
7 // displays the first two terms which is always 0 and 1
8 printf("Fibonacci Series: %d, %d, ", t1, t2);
9 nextTerm = t1 + t2;
10
11 while (nextTerm <= n) {
12 printf("%d, ", nextTerm);
13 t1 = t2;
14 t2 = nextTerm;
15 nextTerm = t1 + t2;
16 }
17
18 return 0;
19}
20
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}