TO FIND FIBONACCI SERIES USING C PROGRAM





Code 1:
1. Write a program to generate the Fibonacci series in c
2. Write a program to print Fibonacci series in c
3. Basic c programs Fibonacci series
4. How to print Fibonacci series in c
5. How to find Fibonacci series in c programming
6. Fibonacci series in c using for loop

#include<stdio.h>
int main(){
    int k,r;
    long int i=0l,j=1,f;

    //Taking maximum numbers form user
    printf("Enter the number range:");
    scanf("%d",&r);

    printf("FIBONACCI SERIES: ");
    printf("%ld %ld",i,j); //printing firts two values.

    for(k=2;k<r;k++){
         f=i+j;
         i=j;
         j=f;
         printf(" %ld",j);
    }
  
    return 0;
}

Sample output:
Enter the number range: 15
FIBONACCI SERIES: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Code 2:
1. Fibonacci series using array in c
2. Fibonacci series program in c language
3. Source code of Fibonacci series in c
4. Wap to print Fibonacci series in c

#include<stdio.h>
int main(){

    int i,range;
    long int arr[40];

    printf("Enter the number range: ");
    scanf("%d",&range);

    arr[0]=0;
    arr[1]=1;

    for(i=2;i<range;i++){
         arr[i] = arr[i-1] + arr[i-2];
    }

    printf("Fibonacci series is: ");
    for(i=0;i<range;i++)
         printf("%ld ",arr[i]);
  
    return 0;
}

Sample output:
Enter the number range: 20
Fibonacci series is: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

Code 3:
1. Fibonacci series in c using while loop
2. C program to calculate Fibonacci series
3. C program to display Fibonacci series
4. Fibonacci series in c with explanation
5. C code to generate Fibonacci series

#include<stdio.h>
int main(){
    int k=2,r;
    long int i=0l,j=1,f;

    printf("Enter the number range:");
    scanf("%d",&r);

    printf("Fibonacci series is: %ld %ld",i,j);

    while(k<r){
         f=i+j;
         i=j;
         j=f;
         printf(" %ld",j);
          k++;
    }
  
    return 0;
}


Sample output:
Enter the number range: 10
Fibonacci series is: 0 1 1 2 3 5 8 13 21 34

Code 4:
1. Sum of Fibonacci series in c

#include<stdio.h>
int main(){
    int k,r;
    long int i=0,j=1,f;
    long int sum = 1;

    printf("Enter the number range: ");
    scanf("%d",&r);

    for(k=2;k<r;k++){
         f=i+j;
         i=j;
         j=f;
         sum = sum + j;
    }

    printf("Sum of Fibonacci series is: %ld",sum);
  
    return 0;
}

Sample output:
Enter the number range: 4
Sum of Fibonacci series is: 4


Algorithm:

What is Fibonacci series?

Logic of Fibonacci series

Definition of Fibonacci numbers:


We assume first two Fibonacci are 0 and 1
A series of numbers in which each sequent number is sum of its two previous numbers is known as Fibonacci series and each numbers are called Fibonacci numbers. So Fibonacci numbers is

Algorithm for Fibonacci series 

Fn = Fn-2 + Fn-1

Example of Fibonacci series:

0 , 1 ,1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55  ...

5 is Fibonacci number since sum of its two previous number i.e. 2 and 3 is 5
8 is Fibonacci number since sum of its two previous number i.e. 3 and 5 is 8 and so on.






10. Write a c program to add two numbers without using addition operator.
11. Write a c program to subtract two numbers without using subtraction operator.
15. Write a c program to solve quadratic equation.
18. Write a c program which passes structure to function.
28. Write a c program which takes password from user.
29. Write a scanf function in c which accept sentence from user.
30. Write a scanf function in c which accept paragraph from user.

44 comments:

Unknown said...

Plese Correct the line where "While" starts.........By

while(k<=r)

Using For loop The programa is.....
void main()
{
int i=0,j=1,k,r,f;
clrscr();
printf("Enter the number range:");
scanf("%d",&r);
printf("\nFIBONACCI SERIES: ");
printf("%d %d",i,j);
for (k = 2; k <= r; k++)
{
f = i + j;
i = j;
j = f;
printf(" %d",j);
}
getch();
}

"Thanks everybody for the program"

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!

Anonymous said...

Thanks you very much

saysuri said...

void main()
{
int i,a=0,b=1,c=0,n;
clrscr();
printf("\n Enter the lenth of the sequence: ");
scanf("%d",&n);
if(n==0)
{
printf("\nPlease enter more than 0 and try again.");

}

else
{
if(n==1)
{
printf("\n The fibonacci serice of given length is: ");
printf("\n\n %d",a);
// getch();
}
else if(n==2)
{
printf("\n The fibonacci serice of given length is: ");
printf("\n\n %d\t%d",a,b);
}
else
{
printf("\n The fibonacci serice of given length is: ");
printf("\n\n %d\t%d",a,b);
for(i=3;i<=n;i++)
{
c=a+b;
a=b;
b=c;
printf("\t%d",c);
}
}
}
getch();
}

Anonymous said...

#include
#include
#include
void main()
{
int n,i,c;
int a=0;
int b=1;
clrscr();
printf("Enter the number of terms=");
scanf("%d",&n);
printf("Fibonacci Series");
printf("\n%d\n%d"a,b);
for (i=3;i<=n;i++)
{
c=a=b;
a=b;
b=c;
printf("\n%d",c);
}
getch();
}

saumya pandey said...

thanks a lot this is great

Anonymous said...

write a c program to implement the single shorted path problem.






thank you.

Unknown said...

Thank u very much for Fibonacci series post.

Kifle Tadesse said...

Thank u very much for Fibonacci series post.but i also need wap Fibonacci series using iterative function

Kifle Tadesse said...

and cosine series

Murali Nimmala said...

Thanks its helped me.

Unknown said...

#include
#include
void main()
{
int i=0,j=1,k,n,count=1;
printf("No. of elements");
scanf("%d",&n);
while(count<=n)
{
printf("%d\t",i);
k=i;
i=i+j;
j=k;
count++;
}
getch();
}
REPLY

Anonymous said...

what will b the output

char * p="Hello";

?=(*p)*;

Anand said...

A simple way to print fibonacci numbers.

#include
main()
{
int a = 0, b = 1, c;
printf("Enter range");
scanf("%d\n",&range);
if(range)
printf("%d ",a);
while(--range)
{
c = a + b;
a = b;
b = c;
printf("%d ",a);
}
}

zaid said...

#include
#include
void main()
{
clrscr();
int a=0,b=1,c=0,n;
cout<<"Enter the number of terms you wanna see: ";
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
getch();
}

Anonymous said...

can you please solve this??

Write a program to calculate the sum of former 40 numbers of series 2/1, 3/2, 5/3, 8/5, 13/8, 21/13,……

wawen said...

How to write a program that will display the sum of the given range.
Sample output: Enter number of range to be added: 5
The sum of given range is: 15

Ramiro said...

Everything is very open with a clear description of the issues. Many thanks for sharing!

Greetings from Torrent

Pradeep Tiwari said...

Questions : - Sir please help out on this.?
1.Print the following pattern:
A B C D E D C B A
A B C D C B A
A B C B A
A B A
A

2. Generate Fibonacci series from 1 to 100 and print it in reverse order.

3. Write an efficient program to reverse characters of each word in a file and write an output file in the same format with all words reversed.

4. Explain the order of complexity in Big-Oh notation, and time taken to process?

5. Work out an algorithm to predict the best times to buy and sell a stock over a 60-day period. Use a suitable data structure so that the “n” th element is the price of the stock on day “n”.
ex. 1st element is stock price on day one, 60th element is stock price on day 60.Assume that you start out with 10,000 INR, and value of stock on day 1 is INR 10. Make up any data that you wish for the stock prices. Please provide the input dataset and a working program.

Unknown said...

here is a simplest way
/* Fibonacci Series c language */
#include
#include
void main()
{
int f=0,s=1,ne=0,n,i;
clrscr();
printf("Enter any integer value\n");
scanf("%d",&n);
printf("%d",f);
for (i=0;i<n;i++)
{
ne=f+s;
printf("+%d",ne);
s=f;
f=ne;
}
getch();
}

Mohammed Shafeeque said...

Fibonacci series
=============
#include

void main()
{
int num,i=0,j=1,k,n;
printf("Enter the number of elements: \n");
scanf("%d",&num);
i=-1;
for(n=0;n<num;n++)
{
k=i+j;
printf("%d ",k);
i=j;
j=k;
}
}

Mohammed Shafeeque said...

Ans 2:
#include

void main()
{
int num=100,i=0,j=1,k=0,n=0;
i=-1;
k=i+j;
//FINDING LAST ELEMENT
while(1)
{
k=i+j;
if(k>num)
break;
i=j;
j=k;
}
//PRINTING OUTPUT
while(j>=1)
{
k=j-i;
printf("%d ",j);
j=i;
i=k;
}
//ADDING LAST 0
printf("0\n");
}

Unknown said...

idea ok. but not working properly for range=0;
i corrected it.

#include
#include

main()
{
int a = 0, b = 1, c=0, range=0;
clrscr();
printf("Enter range");
scanf("%d",&range);
printf("range %d", range);
getch();
if(range)
while(--range)
{
c = a + b;
a = b;
b = c;
printf("\n%d ",a);
}
else
printf("%d",a);
getch();
return (0);
}

Anonymous said...

write a program to find a. surface area (A=apr2)
b. volume (v=4/3 p3)

Anonymous said...

Great post... but the fab numbers start at 1 not 0. SHould be a quick fix :)

Unknown said...

/* Fibonacci Series c language */
#include
#include
void main()
{
int n1=0,n2=1,n3=0,n,i;
clrscr();
printf("Enter any integer value\n");
scanf("%d",&n);
for (i=0;i<n;i++)
{
n3=n1+n2;
printf("+%d",n3);
n1=n2;
n2=n3;
}
getch();
}

Unknown said...

can anyone solve this

Sam is a 6th grader, who's got an assignment to check it a number belongs to the Fibonacci series or not. But apparently his friends have called him out to play a game of Cricket. If Sam writes down the series and verifies it all, if would take too long and would probably miss his match. Can you help him solve his problem through a program ?

Input The first line of the input would contain the number of test cases T. Followed by T list of numbers.

Output For a particular test case T, if the number is present in the Fibonacci series, print Y followed by the position of the number in the Fibonacci series. Else print N followed by NOT PRESENT

(Since 1 is present twice in the series, print both the occurrences)

Unknown said...

sample Input (Plaintext Link)
5
1
8
4
7
21
Sample Output (Plaintext Link)
Y 2 3
Y 7
N NOT PRESENT
N NOT PRESENT
Y 9

Unknown said...

sir pls tell me c programme for n even numbers using break and continue

Unknown said...

Write a program containing a recursive function that computes and displays the nth Fibonacci number, given the value for n.

please send me this program

Unknown said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
Unknown said...

#include
int main(){
int k,r;
int i=0,j=1,f;
printf("Enter the number range:");
scanf("%d",&r);
printf("FIBONACCI SERIES: ");
printf("%d %d",i,j);

for(k=2;k<r;k++){
f=i+j;
i=j;
j=f;
printf(" %d",f);
}
return 0;
}

Unknown said...

Can anyone help me?

Write a recursive function fast_fib to compute a pair of Fibonacci numbers,
F( n + 1) and F( n ). Function fast_fib should make only one recursive call.
Algorithm
if n is 1
The pair to send back is 1, 1.
else
Use fast_fib to compute F( n ) and F( n − 1).
The pair to send back is [F( n ) + F( n − 1)], F( n ).

Unknown said...

thanks for your answers

Enaan Farhan said...

After many search i got the correct one which i want. Thank u

mehul jain said...

#include

int main(void)
{
int n,i;
scanf("%d",&n);
int a[n];
a[0]=0;
a[1]=1;
for(i=0;i=2)
{
a[i]=a[i-2]+a[i-1];
printf(" %d",a[i]);
}
else
printf(" %d",a[i]);
}
return 0;
}

Unknown said...

Please help on this:

Using a recursive function write a C66 program to display the numbers from 10 to 20

Unknown said...

please help me with this: Assuming a is 14 and b is 25 show what is printed by writeln(a,'+',b,'=',a+b);

Shivam Kumar said...

nice one

Unknown said...

can any one teach me c programming language

Unknown said...

Fibonacci using pointers...can anyone help me now

Unknown said...

anyone please

Unknown said...

print 1 -2 3 -4 5 -6...n using loop

please comment urgent