Monday, February 2, 2015

C Programs using Conditional and Control Statements

                        FIBBONACCI SERIES
EX.NO:2

AIM
            To write a C program to generate the Fibonacci series

ALGORITHM
Step-1: Start the program
Step-2: Enter the number
Step-3: Check the number whether the number is zero or not. If zero print Zero value. If  
             not zero go further.
Step-4: Set a loop up to the given number.
Step-5: fib=fib+a;
            a=b;
            b=c;
Step-6: Every increment in the loop prints the value of fib.
Step-7: After the execution of the loop stops the program

PROGRAM
#include<stdio.h>
main()
{
            int num,fib=0,a=0,b=1,i;
            printf(“Enter the number”);
            scanf(“%d”,&num);
            printf(“\n FIBBONACI SERIES\n”);
            if(num==0)
                        printf(“0”);
            else
            {
                        for(i=0;i<num;i++)
                        {
                                    fib=fib+a;
                                    a=b;
                                    b=fib;
                                    printf(“%d\t”,fib);
                        }}}


 OUTPUT
Enter the number 5
FIBONACCI SERIES
0 1 1 2 3


RESULT: Thus a c program to implement Fibonacci series is executed. 

No comments:

Post a Comment