Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!



LC3PROLC3PRO Member Posts: 16
Write a program in C that will generate the Fibonacci sequence of numbers. The Fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21,... or the next number is the sum of the previous two numbers. Generate 24 of the numbers in the sequence, starting with 0, and put each number on a separate line
plz help me!!!!!!!!!!!


  • connectconnect Member Posts: 1
    Although your problem can be solved using an array from 24
    elements, the following code seems to me more rational. Here,
    function fibonacci() is recursive, that is, it calls itself.

    #include "stdio.h"
    #include "conio.h"

    int fibonacci(int up_to);

    int main(void)
    register int i;

    return 0;

    int fibonacci(int up_to)
    if(up_to==1) return 0;
    else if(up_to==2) return 1;
    else return fibonacci(up_to-1)+fibonacci(up_to-2); //recursion
  • LC3PROLC3PRO Member Posts: 16
    Thanks, do you know any free C compiler so I can check these ?
  • craniumcranium Member Posts: 6
    [b][red]This message was edited by cranium at 2004-11-12 12:11:38[/red][/b][hr]
    this is my solition without using array.....of course maybe better to use s up to us:-)play play and play around,and im new about programming too...

    int x, s, counter;
    int s1;
    x=0; //prev s
    s=1; //new sum
    s1=1; //prev sum
    counter=0; //my counter

    //use while loop
    while (counter<=20)
    print((s1)+" ");
    x =s;

    counter=counter+1; //counter increment

    //end while


Sign In or Register to comment.