Pages

Sunday, 2 September 2012

WAP to print fibonacci series till n terms

WAP to print fibonacci series till n terms
Example: n=6
Output:0 1 1 2 3 5
#include <stdio.h>
#include <conio.h>
void main()
{
    int n,a=0,b=1,c=0;
    printf("Enter the number of terms");
    scanf("%d",&n);
    printf("%d %d ",a,b);
    for(int i=3;i<=n;i++)
    {
        c=a+b;
        printf("%d ",c);
        a=b;
        b=c;
        }
        }

No comments:

Post a Comment