Click the Follow Button

C; How to write Fibonacci Series in C.

 Program:

#include<stdio.h>

int main()
{
    int n, c;
    int a = 0;
    int b = 1;

    printf("Enter a number: ");
    scanf("%d", &n);
    printf ("%d  %d  ", a, b);

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


Input:

Enter a number: 10

Output:

0  1  1  2  3  5  8  13  21  34  55  89  144

Comments

Popular Posts

TIC - TAC - TOE

Prime and not prime number

do_while loop is to do something again and again