Thursday, October 20, 2011

tugas bpl fibonachi dan faktorial

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication20
{
    public class program
        {
            public program(int a, int b)
            {
                if (a==1)
                {
                    int i=1;
                    int x=1;
                while (i<=b)
                {
                x=(x*i);
                i = i + 1;
                }
                Console.WriteLine("faktorial = {0}", x);
                }
                if (a == 2)
                {
                    int i = 1;
                    int x = 1;
                    int y = 1;
                    Console.Write("fibonaci = {0}", x);
                    Console.Write(" {0}", y);
                    while (i <= (b - 2))
                    {

                        y = (y + x);
                        x = (y - x);
                        Console.Write(" {0}", y);
                        i = (i + 1);
                    }
                }
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                program P1 = new program(1,5);
                program P2 = new program(2,5);
                Console.WriteLine();
            }
        }
    }

No comments:

Post a Comment