answersLogoWhite

0


Best Answer

#include<stdlib.h>

#include<conio.h>

#include<stdio.h>

void main (void)

{

clrscr();

int i;

int a[10];

a[0]=0;

a[1]=1;

printf("First 10 Fibonacci numbers are :\n");

printf("%d\n%d\n",a[0],a[1]);

for(i=2;i<10;i++)

{

a[i]=a[i-1]+a[i-2];

printf("%d\n",a[i]);

}

getch();

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

8y ago

The same way it works in any other language; the nth term is the sum of terms n-1 and n-2, where the first two terms are 0 and 1.

To represent the sequence, use a fixed-size array to store the count of terms (t) that you require, then set the first two terms to 0 and 1. Then traverse the array from element [2] to [t-1], assigning the sum of the previous two elements to the current element.

The following example instantiates a static array of 100 terms that is initialised on first use:

#include<stdio.h>

const int max_fib_terms = 100;

const int* const fib() {

static int fib[max_fib_terms];

static bool init = false;

if (!init) {

init = !init;

fib[0]=0;

fib[1]=1;

int n;

for (n=2; n<max_fib_terms; ++n)

fib[n]=fib[n-1]+fib[n-2];

}

return &fib[0];

}

int main() {

for (int i=0; i<max_fib_terms; ++i)

printf("%u, ", fib()[i]);

printf("\b\b \n");

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

program to Display Fibonacci series (0,1,1,2,3,5,8,13------)

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

112358

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to generate the Fibonacci Series using array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a c program to generate Fibonacci series using copy constructor?

#include #include void main(void) { int i,j,k,n; clrscr(); i=0; j=1; printf("%d %d ",i,j); for(n=0;n&lt;=5;n++) { k=i+j; i=j; j=k; printf("%d ",k); } getch(); }


Write a java program to print the last digit in Fibonacci series?

Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.


Write a shell program to generate fibnacci series using while loop?

//WAP to print fibonacci series using do-while loop.? using System; class Fibonacci { public static void Main() { int a=1,b=1; int sum=0; Console.Write("Enter Limit:"); int n=Int32.Parse(Console.ReadLine()); Console.Write(a); Console.Write(b); do { sum=a+b; a=b; b=sum; Console.Write(sum); } while(sum&lt;n); } } By-Vivek Kumar Keshari


Write a java program to generate the Fibonacci Series using for loop?

class Fibonacci { public static void main(String args[]) { System.out.println("enter the number upto u want"); int number=Integer.parseInt(args[0]); int a=0,b=1,c=0; System.out.print(a+" "+b); for(int i=1;i&lt;=number;i++) { c=a+b; System.out.print(c+" "); a=b; b=c; } } } the number are given to the run time where are print the series eg: 5 0 1 1 2 3 5 8 13................


Write a java program to print the result in the series?

If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).

Related questions

Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


Write a c program to generate Fibonacci series using copy constructor?

#include #include void main(void) { int i,j,k,n; clrscr(); i=0; j=1; printf("%d %d ",i,j); for(n=0;n&lt;=5;n++) { k=i+j; i=j; j=k; printf("%d ",k); } getch(); }


Write a java program to print the last digit in Fibonacci series?

Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.


Write a program using while loop that generates Fabonaci series up to 200?

//to generate Fibonacci series upto a range of 200....(in C).... #include&lt;stdio.h&gt; main() { int a,b,c,i; a=0; b=1; printf("\n FIBONACCI SERIES .....\t"); i=1; while(i&lt;=(200-2)) { c=a+b; printf("\t%d",c); a=b; b=c; i++; } }


Write a shell program to generate fibnacci series using while loop?

//WAP to print fibonacci series using do-while loop.? using System; class Fibonacci { public static void Main() { int a=1,b=1; int sum=0; Console.Write("Enter Limit:"); int n=Int32.Parse(Console.ReadLine()); Console.Write(a); Console.Write(b); do { sum=a+b; a=b; b=sum; Console.Write(sum); } while(sum&lt;n); } } By-Vivek Kumar Keshari


Write a c program to accept a numbers and generate square root cube and exponential values?

write a c program to accept a number and generate a square root cube and exponential values


Write a java program to generate the Fibonacci Series using for loop?

class Fibonacci { public static void main(String args[]) { System.out.println("enter the number upto u want"); int number=Integer.parseInt(args[0]); int a=0,b=1,c=0; System.out.print(a+" "+b); for(int i=1;i&lt;=number;i++) { c=a+b; System.out.print(c+" "); a=b; b=c; } } } the number are given to the run time where are print the series eg: 5 0 1 1 2 3 5 8 13................


Write a java program to print the result in the series?

If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).


Algorithm of Fibonacci series in c?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; int fib(int a); main() { int a; clrscr(); scanf("%d",&amp;a); for(int i=0;i&lt;a;i++) printf("%d\n",fib(i)); } int fib(int a) { if(a==0) return 0; if(a==1) return 1; else return (fib(a-1)+fib(a-2)); }


How do you write a program to print Fibonacci series of n numbers using recursion in cpp?

#include&lt;iostream&gt; unsigned fib (unsigned term, unsigned a=0, unsigned b=1) { if (term&lt;1) return a; return fib (--term, a+b, a); } int main() { std::cout &lt;&lt; "Fibonacci (1000th term): " &lt;&lt; fib (1000) &lt;&lt; std::endl; }


Write a C program to print the following series 112 122 . 1n2?

write a program to print the series 1/12+1/22+.........+1/n2 ?


Write a Fibonacci function then takes an input from the user in main program and pass to function which prints Fibonacci series up to this number in c language by using while statement?

#include#includevoid fibonacci(int x){int f=0,m=-1,n=1,i=0;while(i