# Fibonacci Series Using Array And For Loop - C Programming Examples

As we have started C Programming coding with Example Series, We have published last posts

"Write A Program For SUM of Infinite HP"

"Write A Program To Find SUM of AP" and

"Write A Program To Find SUM of GP Sequence".

We have chosen to start with Arithmetic Series and in this post you will find some basic idea and some useful concepts about Fibonacci Numbers .You can download C Codes below.Please let us know your feedback.

A working Example of FOR Loop

Example:

#include <stdio.h>

int main()

{

int x;

/* The loop goes while x < 10, and x increases by one every loop*/

for ( x = 0; x < 10; x++ )

{

/* Keep in mind that the loop condition checks

the conditional statement before it loops again.*/

printf( "%d\n", x );

}

getchar();

}

Arrays are of two types:

A. One-dimensional arrays

B. Multidimensional arrays

"Write A Program For SUM of Infinite HP"

"Write A Program To Find SUM of AP" and

"Write A Program To Find SUM of GP Sequence".

We have chosen to start with Arithmetic Series and in this post you will find some basic idea and some useful concepts about Fibonacci Numbers .You can download C Codes below.Please let us know your feedback.

In this post we are doing again Fibonacci Series but with different approach.In last post "Fibonacci Progression Using While Loop" you will see how to generate Fibonacci Numbers by using concepts of Do-While Loop.In this post we will talk about another loop i.e. For Loop and side by side Concept of Arrays will be discussed and demonstrated.

__Fibonacci Series - Sequence ( Using Array And For Loop ) Video Tutorial(See C- Codes Below )__:

__For Loop Concept__: FOR Loops are the most useful type. The syntax for a for loop is

for ( variable initialisation; condition; variable update ) {

Code to execute while the condition is true

}

Code to execute while the condition is true

}

A working Example of FOR Loop

Example:

#include <stdio.h>

int main()

{

int x;

/* The loop goes while x < 10, and x increases by one every loop*/

for ( x = 0; x < 10; x++ )

{

/* Keep in mind that the loop condition checks

the conditional statement before it loops again.*/

printf( "%d\n", x );

}

getchar();

}

__Array Concept__: Arrays may be defined as a kind of data structure that can store a fixed-size sequential collection of elements of the same type.An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

A. One-dimensional arrays

B. Multidimensional arrays

To declare an array in C, specifies the type of the elements and the number of elements required by an array as follows −

type arrayName [ arraySize ]

Initialising array in C using a single statement −

type arrayName [ arraySize ]

Initialising array in C using a single statement −

double MoneyBalance[5] = {1000.0, 2.0, 3.4, 7.0, 50.0};

If you omit the size of the array, an array just big enough to hold the initialisation is created −

double MoneyBalance[] = {1000.0, 2.0, 3.4, 7.0, 50.0};

More of Fibonacci Sequence Tutorials.

C Program -

#include<stdio.h>

int main()

{

int i,range;

long int arr[40];

printf("\nEnter 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]);

printf("\nFibonacci Ends \n\n");

delay(5000);

return 0;

}

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

If you omit the size of the array, an array just big enough to hold the initialisation is created −

double MoneyBalance[] = {1000.0, 2.0, 3.4, 7.0, 50.0};

More of Fibonacci Sequence Tutorials.

__Write A Program In C To Find Fibonacci Numbers Progression - Series - Sequence to Nth Term__:C Codes are written and tested in TuboC/C++ IDE as you can see in Video:C Program -

#include<stdio.h>

int main()

{

int i,range;

long int arr[40];

printf("\nEnter 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]);

printf("\nFibonacci Ends \n\n");

delay(5000);

return 0;

}

Write A Program in C to Find Fibonacci series up to Nth terms (Use Of Array and FOR Loop)

__Result__:-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

That is an extremely smart written article. I will be sure to bookmark it and return to learn extra of your useful information. Thank you for the post. I will certainly return.

ReplyDeleteThanks for your patronage.

DeleteHey keep posting such good and meaningful articles.

ReplyDelete