সোমবার, ২৭ এপ্রিল, ২০২০

Write a C program to print a Fibonacci series of a given range.


Write a C program to print a Fibonacci series of a given range.


Problem name:  Write a C program to print a Fibonacci series of a given range.
Algorithm:
Step 1: Start
Step 2: Input the value of N
Step 3: Initialized the value first = 0, second=1
Step 4: Print the first value
Step 5: Initialized the value c=0
Step 6: While c<n repeat the step 7
Step 7: next= first + second, first = second, second = next, c ++
Step 8: Print the value of next
Step 9: End


C Program:



#include<stdio.h>
int main()
{
    int n, first=0, second=1,next,c;
    scanf("%d",&n);
    printf("First %d terms ",n);
    for (c=0; c<n; c++)
    {
        if (c<=1)
            next = c;
        else
        {
            next = first+second;
            first=second;
            second=next;
        }
        printf("%d\n",next);
    }
    return 0;
}
 


লেবেলসমূহ:

0টি মন্তব্য:

একটি মন্তব্য পোস্ট করুন

এতে সদস্যতা মন্তব্যগুলি পোস্ট করুন [Atom]

<< হোম