Saturday, 28 January 2017

Fibonacci series upto ‘n’ numbers in C ~ mkniit ~ gniitsolution

C program for Fibonacci series upto ‘n’ numbers. It is a simple source code that provides the output of an actual Fibonacci sequence up to n numbers. For this C program, questions may asked like “write a C program to find the Fibonacci series & sample Fibonacci program in C“. Take care of a questions for your interviews or students exam. This is a totally free of cost code.

CREATE FIBONACCI SERIES UP TO N NUMBERS IN C

Create a Fibonacci series up to n numbers in C program. It is used to create the Fibonacci series in any particular range of value or up to n terms by looping statement. Basic condition is (cn=2;cn<rge;cn++).
C CODE:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Title: Fibonacci series
Author: Vinoth Selvaraj
*/
//Header files
#include <stdio.h>
#include <conio.h>
void main()
{
    //Program variables
    int cn,rge,num1=0,num2=1,num3;
    clrscr(); //Function to clear previous output
    //Display function
    printf("Enter the range of Fibonacci series to generate : ");
    scanf("%d",&rge); //Getting input function
    printf("%d-->%d-->",num1,num2);
    //Creating fibonacci series.
    for(cn=2;cn<rge;cn++) //Looping statement
    {
        num3=num1+num2;
        printf("%d-->",num3);
        num1=num2;
        num2=num3;
    }
    getch();
}

No comments:

Post a Comment