1.

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(PI());
            Console.ReadLine();

        }
        static double PI()
        {
            double pi, t;
            int n, sign;

            n = 1;
            sign = 1;
            pi = 0;
            t = 0;

            do
            {
                t =4.0 / ((2 * n) - 1);//if n=0,則為2n+1
                pi += t * sign;
                sign = -sign;
                n++;
            } while (t > 0.00001);
            return pi;
        }

    }
}


2.

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

namespace starConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.WriteLine("請輸入: ");
            n = int.Parse(Console.ReadLine());
            three(n);
            Console.ReadLine();

          
        }
       
        static void three(int n)
        {
            int i, j;
            for (i = 0; i < n; i++)
            {
                for (j = 0; j < n - i - 1; j++)
                {
                    Console.Write(" ");
                }
                for (j = 0; j < i * 2 + 1; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }

        }

 

          
       
    }
}

 

3.

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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n,m,x;
            Console.WriteLine("請輸入 n : ");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine("請輸入 m : ");
            m = int.Parse(Console.ReadLine());
            if (m == 0)
                Console.WriteLine("0");
            x = n - m;


            Console.WriteLine("執行結果:"+nLeveln(n)/(nLevelm(m)*nLevelx(x)));
            Console.ReadLine();
        }
        static int nLeveln(int n)
        {
            if (n > 1)
            { return n * nLeveln(n - 1); }
            else return n;
        }
        static int nLevelm(int m)
        {
            if (m > 1)
            { return m * nLevelm(m - 1); }
            else return m;
        }
        static int nLevelx(int x)
        {
            if (x > 1)
            { return x * nLevelx
                (x - 1); }
            else return x;
        }
    }
}


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Joy 的頭像
    Joy

    正Man's World

    Joy 發表在 痞客邦 留言(0) 人氣()