Fibonacci Series in C Program with Source Code
Contents
Introduction
The C programming language is a procedural programming language. Between 1969 and 1973, Dennis Ritchie worked on the project. It was created primarily as a system programming language for developing operating systems. Low-level memory access, a small collection of keywords, and a clean style are all qualities that make C language excellent for system programming, such as operating system or compiler development.
Why Learn C Programming Language?
Because it mixes the characteristics of high-level languages with the functionalism of assembly language, C is often referred to as a middle-level computer language. The manipulation of bits, bytes, and addresses in C gives the programmer more control over how the program will behave and more direct access to the underlying hardware mechanisms.
Working programmers influenced, influenced, and field-tested C. As a result, C provides the programmer with exactly what he or she want. C++ is a more advanced version of the C programming language. C++ incorporates all of the features of C, as well as support for object-oriented programming (OOP). Furthermore, C++ includes numerous enhancements and features that make it a “better C,” regardless of whether or not it is used for object-oriented programming.
Fibonacci Series in C Program
The Fibonacci numbers, typically abbreviated as Fₙ, are a mathematical series in which each number is the sum of the two preceding ones. The series usually begins with 0 and 1, while some authors skip the first two terms and begin with 1 and 1 or 1 and 2.
In C, the Fibonacci series defined the recurrence relation of numeric sequences.
It generates the next number by adding the second and third terms to the previous number instead of utilizing the first term. It can be done as the user requests till the number of terms is reached.
Except for the initial two numbers of the series (0, 1), every other third term is produced by adding the previous two numbers in Fibonacci sequence such as 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on.
- Example 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
- Example 2: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, …………
The best way to learn is to do. Hence, what better way to learn C programming language (if you know the basics) than to code a Fibonacci Series. In this tutorial we are going to code a Fibonacci Series using C programming language. Keep in mind this is a project for absolute beginners and intermediate programmers as well.
Source Code
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
int x=0,y=1,z,i,number;
printf("Enter your number of how many times you want to print series: ");
scanf("%d",&number);
// First we print 0 and 1, the first two numbers that are same throught every fibonacci series
printf("\n%d %d",x,y);
// Now we need to start loop from 2 because 0 and 1 already we have print
for(i=2;i<number;++i)
{
z=x+y;
printf(" %d",z);
x=y;
y=z;
}
return 0;
}
Output
- Output Screenshot 1 :
- Output Screenshot 2 :
- Output Screenshot 3 :