{ A destination to learn coding }

Fibonacci Series - Algorithm and Code


#include<stdio.h>

int sumFib(int n)
{
  int a=0, b=1, c, sum=0,i;

  for(i=0;i<n;i++)
  {
    sum+=a;
    printf("%d \t",a);
    a=a+b;
    c=a;
    a=b;
    b=c;
  }

  return sum;
}

int main()
{
  int n,ans;

  printf("Enter the value of n\n");
  scanf("%d",&n);

  ans=sumFib(n);
  printf("\nThe sum is %d",ans);
  return 0;
}

Algorithm

/*Environment One (main)*/
  1. Begin
  2. var int n, ans
  3. Input n
  4. ans=sumFib(n)
  5. print ans
  6. End
/*Environment 2 - Function sumFib()*/
  1. var int a=0, b=1, c, sum=0, i=0
  2. while i
    1. sum=sum+a
    2. print a
    3. a=a+b
    4. c=a
    5. a=b
    6. b=c
    7. i=i+1
  3. return sum