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//Program Name: Print fibonacci series using for loop upto n term
2// for e.g 1, 1, 2, 3, 5, 8
3#include <stdio.h>
4void main()
5{
6 int s1=0,s2=1; //initializing first two numbers
7 int nextNum=0,SumUpto=0;
8 printf("\n\n\tPlease enter number up to which print Fibonacci series is required \t");
9 scanf("%d",&SumUpto);
10 //printing first two numbers
11 printf("\n\tfibbonacci Series up to %d is ",SumUpto);
12 printf("\n\n\t%d %d",s1,s2);
13 for(nextNum=2;nextNum<=SumUpto;)
14 {
15 s1=s2;
16 s2=nextNum;
17 printf(" %d",nextNum);
18 nextNum=s1+s2;
19 }
20}
1#include <stdio.h>
2void main()
3{
4 int s1=0,s2=1; //initializing first two numbers
5 int nextNum=0,SumUpto=0;
6
7 printf("\n\n\tPlease enter number up to which print Fibonacci series is required \t");
8 scanf("%d",&SumUpto);
9 printf("\n\tfibbonacci Series up to %d is ",SumUpto);
10 printf("\n\n\t%d %d",s1,s2);
11 for(nextNum=2;nextNum<=SumUpto;)
12 {
13 s1=s2;
14 s2=nextNum;
15 printf(" %d",nextNum);
16 nextNum=s1+s2;
17 }
18}