Sunday, December 15, 2019

Write a program for Fibonacci series.

For example:0 1 1 2 3 5 8 13......

Program:
#include <stdio.h>
void main()
{
    int s=0,n,a,b;
    a=0,b=1;
    printf("enter any no:");
    scanf("%d",&n);
    printf("Fibonacci series:\n");
    printf("%d",a);
    printf("\t%d",b);
    printf("\t");
    for(int i=0;i<n;++i){
        s=a+b;
        a=b;
        b=s;
        printf("%d",s);
        printf("\t");
    }
}

No comments:

Post a Comment

Write a program to find gcd of two numbers using recursion.

About:  The process in which a function calls itself is called recursion and the corresponding function is called as recursive function. ...