Thursday, 27 February 2014

Write a ‘C’ program to to generate a triangle with fibonacci numbers (series given bellow) as elements of every row. e.g., forn=5, the output should be, 1 1 1 1 1 1 2 1 1 2 3 1 1 2 3 5

#include<stdio.h>
main()
{  
    int a=1,b=1,i=1,n,temp,j;
    printf("\nEnter number of rows=");
    scanf("%d",&n);
    printf("\nThe fibonacci series is\n");
    j=1;
    while(j<=n)
    {
        a=1;
        b=1;
        i=1;
        while(i<=j)
        {
            printf("%10d",a);
            temp=a;
            a=b;
            b=temp+a;
            i++;
        }
        printf("\n");
        j++;
    }
}

No comments:

Post a Comment