C program to print the Fibonacci series.

 

C program
C PROGRAM

C program to print the  Fibonacci series

#include<stdio.h>
#include<conio.h>
void main() 
{
    int n,first=0,second=1,next,a;
    clrscr();
    printf("enter the number of terms");
    scanf("%d",&n);
    for(a=0;a<n;a++)
    {
    if(a<=1)
    {
      next=a;
      printf ("%d",next);
      }
      else
      {
      first=second;
      second=next;
      next=first+second;
      printf("%d",first);
      }
      }
      getch();
      }

OUTPUT : 

enter the number of terms10
011123581321
Process finished.

No comments:

Post a Comment




Copyright Ⓒ 2022 | Mechpedia | All Right Reserved.