answersLogoWhite

0

I don't program in just C (I use C++) so you may have to change some of the code:

int main()

{

int n;

int last = 1;

int slast = 0;

int numbers[n];

numbers[0] = 1;

for(int i = 1; i < n; i++)

{

numbers[i] = last + slast;

slast = last;

last = numbers[i];

}

return 0;

}

int n needs to be set to however many Fibonacci numbers you want to make.

int last is the last number in the sequence (so far)

int slast is the second last number in the sequence (so far)

int numbers[n] is the int array which holds your numbers

int i is the count for the loop, it is set to 1 because before the loop, I set numbers[0] to 1

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

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 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 c program Fibonacci series using for loop in java?

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


How do i Write a programme to show the fabonasi numbers?

Step 1. Learn the word "Fibonacci"...


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 program to generate the Fibonacci series using non-recursive method?

In c: int fibr(int n) { // Find nth Fibonacci number using recursion. if (n&lt;=2) return 1; // the first two Fibonacci numbers are 1 and 1 return (fibr(n-2)+fibr(n-1)); } int fibi(int n) { // Find nth Fibonacci number using iteration. int temp,last=1,f=1; int i; for (i=3;i&lt;n;++i) { // the first two Fibonacci numbers are 1 and 1 temp=f; f+=last; last=temp; } return f; }


Write a program in Lex to eliminate white space and collect numbers as a token?

write a lex program to delete space from the program


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


Write a program to generate the first 50 perfect numbers?

I don't believe that 50 perfect numbers have ever been found, last time I checked there were only about 47 known perfect numbers. It would also require an extremely powerful computer.


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 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 javascript program for Fibonacci series?

I did this as an answre to some common js questions , the question wasWrite a function which will return you first two times 1, then 2, then 3, then 5 and so on (Fibonacci numbers). Don't use any global variables.var fibonacci = (function () {var arr = [0, 1];return function () {var num = arr[arr.length - 1],len = arr.length;arr.push(arr[len - 1] + arr[len - 2]);return num;};}());//testvar i;for (i = 0; i < 10; i++) {console.log(fibonacci());}//1,1,2,3,5,8,13,21,34,55