Page Contents

## Interview Content

- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions

# Fibonacci series program in C using iteration.

**Ans: **

In this tutorial we are going to learn how to print Fibonacci series in C program using iterative method.

In this program count of output elements of the series is depends upon the input given by users. Program will print n number of elements in a series, where n is a number given by the user as a input.

Before moving directly on the writing Fibonacci series in c program, first you should know

## What is Fibonacci Series?

A Fibonacci series is a series in which next number is a sum of previous two numbers.

**For example :** 0, 1, 1, 2, 3, 5, 8 ……

In Fibonacci Series, first number starts with 0 and second is with 1 and then its grow like,

0

1

0 + 1 = 1

1 + 1 = 2

1 + 2 = 3

2 + 3 = 5 and

so on…

## How our program will behave?

Suppose if someone gives an input 5 then our program should print first 5 numbers of the series.

Like if someone given 5 as a input then our Fibonacci series program which is written in C should print output as,

0, 1, 1, 2, 3

## C program to print Fibonacci series using Iterative methods

```
#include <stdio.h>
#include <conio.h>
int main()
{
int n, first = 0, second = 1, result, i;
printf("Please give an input upto you want to print series : \n");
scanf("%d", &n);
printf("Fibonacci Series is:\n");
for (i = 0; i < n; i++)
{
if (i <= 1)
result = i;
else
{
result = first + second;
first = second;
second = result;
}
printf("%d\n", result);
}
return 0;
}
```

**Output:**

## Explanation of Fibonacci series in C program using Iterative method

- In the above program I have taken 5 variables of integer type.
- Variables are n, i, first, second and result.
- Variable first and second has assigned value 0 and 1 respectively. Because we have assumed that our first and second number of this is series is fixed. And further number we will calculate on the basis of this two first elements.
- Now we have a “for loop”, where the logic is written. This loop will be execute n number of times where n is number given as input.
- result is a variable which will hold the final result after calculation and print each time. If the input is given 0 then program will print 0 and if input is 1 then it will print 0, 1.
- But if it greater than 1 then calculation required and as per calculation it will print the output.
- For 3rd element of the series, result will hold the sum of first and second number.
- After calculation we will assign value of second variable in first variable. And latest calculated value in second variable.
- This new value will be use to calculate next element of the Fibonacci series.
- This logic will be apply for the calculation of all next elements of the Fibonacci series.

I hope above program is now clear to you.

## Also Prepare C interview programs given below

### C Questions on number

- Write a program to reverse an integer in C.
- Write a program in C to check whether an integer is Armstrong number or not.
- Write a program in C to print the fibonacci series using recursive method.
- Write a program in C to check whether a number is palindrome or not using recursive method.
- Write a program in C to add two integer without using arithmetic + operator.

### C Questions on String

##### Latest Uploads on Website

- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program