Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

fibonacci series in c

#include <stdio.h>
// declaring function
int fib(int num)
{
    if (num == 0)
    {
        return 0;
    }
    else if (num == 1)
    {
        return 1;
    }
    else
    {
        return fib(num - 1) + fib(num - 2);
    }
}
int main()
{
    int a;
    printf("enter the number of terms you want to print
");
    scanf("%d", &a);

    printf("fibonacci series upto %d is : ", a);
    for (int c = 0; c <a; c++)
    {
        printf(" %d ", fib(c));
    }
    return 0;
}
 
PREVIOUS NEXT
Tagged: #fibonacci #series
ADD COMMENT
Topic
Name
1+4 =