Results 1 to 8 of 8

Thread: simple cade

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    simple cade

    hi,

    how can i get the output like : 0, 1, 1, 2, 3, 5, 8, 13, 21 ..........
    please help.

  2. #2
    Member
    Join Date
    Mar 2005
    Posts
    56

    Re: simple cade

    Please explain in detail, as the question is really vague.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    Re: simple cade

    hi,

    i m very new in C#. i want to display the output in : 0 , 1 , 1 ,2 , 3, 5, 8 , 13, 21 .....

    for example:

    n=0, output=0
    n=1, output = 1
    n=2, output = 1
    n=3, output = 2
    n=4 output = 3
    n=5, output = 5
    n=6, output = 8
    n=7 output = 13

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: simple cade

    Code:
    Console.Writeline("0, 1, 1, 2, 3, 5, 8, 13, 21 ..........");
    Take my wife...
    Please.
    ba dom
    Seriously what is the information how is it stored?
    Code:
    int[] arr = {0,1,1,2,3,4,6,8};
    for(int i=0;i<arr.Length;i++){
       Console.WriteLine("n="+i.ToString() + " output=" + arr[i].ToString());
    }
    //or
    for(int i=0;i<arr.Length;i++){
    	if(i==arr.Length-1){
    		Console.WriteLine(i.ToString());
    	}
    	else{
    		Console.Write(i.ToString() + ",");
    	}
    }

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    Re: simple cade

    hi,

    if i have 2 textbox, 1 is for keying the number and another 1 is for the display.
    for example, i key in 6 in textbox1, the 8 will display on textbox2. if i key in 100 in textbox1, i want the result will display in textbox2.

    and my number format is : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34..... that means the 1st number + 2nd number = 3rd number

    how can i write it in C#

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: simple cade

    The Fibonacci sequence, you mean, and you'd like to access the nth element of the array?

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: simple cade

    Like this:

    PHP Code:
    public static int Fibonacci(int nint k)
        {
        if (
    1)
            return 
    0;
        else if (
    == 1)
            return 
    1;
        else
        {
            
    int[] = new int[1];
            for (
    int i 01; ++i)
            
    f[i] = 0;
            
    f[1] = 1;
            for (
    int i k<= n; ++i)
            {
            
    int sum 0;
            for (
    int j 1<= k; ++j)
                
    sum += f[j];
            
    f[i] = sum;
            }
            return 
    f[n];
        }
        } 

  8. #8
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    Re: simple cade

    public static int Fibonacci(int n, int k)
    That's some slick code. Nice job.

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width