Beispiel #1
0
    public static void catalan_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CATALAN_TEST tests CATALAN.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 November 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int c = 0;
        int n = 0;

        Console.WriteLine("");
        Console.WriteLine("CATALAN_TEST");
        Console.WriteLine("  CATALAN computes Catalan numbers.");
        Console.WriteLine("");
        Console.WriteLine("  N  exact C(I)  computed C(I)");
        Console.WriteLine("");

        int n_data = 0;

        for (;;)
        {
            Burkardt.Values.Catalan.catalan_values(ref n_data, ref n, ref c);

            if (n_data == 0)
            {
                break;
            }

            int[] c2 = new int[n + 1];

            c2 = Catalan.catalan(n);

            Console.WriteLine("  "
                              + n.ToString().PadLeft(4) + "  "
                              + c.ToString().PadLeft(8) + "  "
                              + c2[n].ToString().PadLeft(8) + "");
        }
    }
Beispiel #2
0
    private static void test005()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST005 tests CATALAN and CATALAN_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int c = 0;
        int n = 0;

        Console.WriteLine("");
        Console.WriteLine("TEST005");
        Console.WriteLine("  CATALAN computes Catalan numbers.");
        Console.WriteLine("  CATALAN_VALUES returns some exact values.");
        Console.WriteLine("");
        Console.WriteLine("  N  exact C(I)  computed C(I)");
        Console.WriteLine("");

        int n_data = 0;

        for (;;)
        {
            Burkardt.Values.Catalan.catalan_values(ref n_data, ref n, ref c);

            if (n_data == 0)
            {
                break;
            }

            int[] c2 = Catalan.catalan(n);

            Console.WriteLine("  " + n.ToString().PadLeft(4)
                              + "  " + c.ToString().PadLeft(6)
                              + "  " + c2[n].ToString().PadLeft(6) + "");
        }
    }