Code Scrappers


Fibonacci series C program


              #include<stdio.h>
              #include<stdlib.h>

              void main()
              {
                  int thirdnum, i, num;

              	   int firstnum = 0, secondnum = 1;

              	   printf("Enter the no. of elements to be displayed : ");

                   scanf("%d",&num);

                   printf("\n%d\t%d",firstnum, secondnum);

                	for(i=2;i<num;++i)
                	{
                        thirdnum = firstnum +secondnum;

                        printf("\t%d",thirdnum);

                        firstnum = secondnum;

                        secondnum = thirdnum ;
                	}

              }
          



Output

    Enter the no. of elements to be displayed : 5

    0       1       1       2       3