Thursday, 18 October 2012

Script Fibonacci c#

 Cara pertama:
============================================================================
//Fibonacci 1
==========================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

          int x = 1, y = 1, z = 1;

          Console.Write("jumlah bilangan Fibonasi yang ingin ditampilkan =");
          int jumlah = Convert.ToInt32(Console.ReadLine());
          for (int i = 0; i < jumlah; i++)
           {
               Console.Write(z + " ");
               z = x + y;
               x = y;
               y = z;
           }
      

        }
    }
}

=========================================================================================




Cara ke-2.:

//Fibonacci 2
==========================================================================
public void fibonacci(int bil)
        {
            int a = 0;
            int b = 1;
            for (int i = 1; i <= bil; i++)
            {
                a = a + b;
                b = a - b;
                Console.Write (a + " ");
            }
        }










=============================================================================


Unduh File via 4shared Download disini !






0 komentar:

Post a Comment

Note: only a member of this blog may post a comment.