Answer to Question #187626 in C for viy

Question #187626

Write a C program for the Fibonacci series of n numbers using array.

    Fi = F(i-1) + F(i-2)

 Example: if n =5

F1 = 1 

F2 = 1       

F3 = F2+ F1 = 1 + 1 = 2

F4 = F3 + F2 = 2 + 1 = 3

F5 = F4 + F3 = 3 + 2 = 5


1
Expert's answer
2021-04-30T16:50:43-0400
#include <stdio.h>

int main()
{
    int num;
    printf("Enter the number of Fibonacci numbers: ");
    scanf("%d", &num);
    if (num > 0)
    {
        printf("F1 = 1\n");
        if (num != 1)
        {
            printf("F2 = 1\n");
            if (num != 2)
            {
                int pp = 1, p = 1, c;
                for (int i = 3; i <= num; ++i)
                {
                    c = p + pp;
                    printf("F%d = F%d + F%d = %d + %d = %d\n", i, i - 2, i - 1, pp, p, c);
                    pp = p;
                    p = c;
                }
            }
        }
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS