CodesJava

Easy learning with example program codes

C program to print fibonacci series


The below program prints a Fibonacci Series without recursion and with recursion. The C printf statement is used to output the result on the screen. A series is called as a Fibonacci series if the each next term of the series is a sum of previous two numbers.

C program to print fibonacci series
a, b, c, d, e

c = a+b
d = b+c
e = c+d

For example,
0 2 2 4 6 10 16 26

Code:

#include <stdio.h>
 
void main()
{
 
int n = 0, a = 0, b = 2;
int c;
int mod;
 
printf ("Fibonacci series with the first 2 numbers as 0 and 2 is: ");  
printf ("%d, %d", a, b);  
 
for (n=0; n<10; n++)  
{  
c = b + a;  
printf ( ", ");
printf ( "%d",c);
 
a = b;  
b = c;  
}
}

Output

Fibonacci series with the first 2 numbers as 0 and 2 is: 
0, 2, 2, 4, 6, 10, 16, 26, 42, 68, 110, 178
Posted in C   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki