函数

1.输出hello wo  public void print()

        {
            Console.WriteLine("hello world!");
            Console.WriteLine("hello world!");
            Console.WriteLine("hello world!");
            Console.WriteLine("hello world!");
            Console.WriteLine("hello world!");            
        }
        static void Main(string[] args)
{
            Program p = new Program();
            p.print;
            p.print;//一个p.print;输出5个hello world

Console.ReadLine();
}

2.加法运算

        public static int Jiafa(int a, int b)
        {
            return a + b;
        }
       static void Main(string[] args)
{
            int a = p.Jiafa(5,3);//调用函数的时候给它输入参数赋值
            Console.WriteLine(a);
            Console.ReadLine(); 
}

3.判断质数

        public void zhishu(int a)
        {

            int count = 0;
            for (int i = 1; i <= a; i++)
            {
                if (a % i == 0)
                {
                    count++;
                }
            }
                if (count == 2) 
                {
                    Console.WriteLine("这个数是质数");
                }
                else
                {
                Console.WriteLine("这个数不是质数");
                }

            }
        static void Main(string[] args)
{
            Program b = new Program();
            Console.Write("请输入数字:");
            int a = int.Parse(Console.ReadLine());
            b.zhishu(a);
            Console.ReadLine();
}

4.判断体重是否正常

        public void tizhong(string a, double b,double c)
        {
            double d = 0;
            if (a == "")
            {
                 d = b - 100;
                if (c >= d - 3 && c <= d + 3)
                {
                    Console.WriteLine("您的体重正常");//return""
                }
                if (c < d - 3)
                {
                    Console.WriteLine("您的体重偏轻");
                }
                if (c > d + 3)
                {
                    Console.WriteLine("您的体重偏胖");
                }

            }

            if (a == "")
            {
                double e = b - 110;
                if (c >= e - 3 && c <= e + 3)
                {
                    Console.WriteLine("您的体重正常");
                }
                if (c < e - 3)
                {
                    Console.WriteLine("您的体重偏轻");
                }
                if (c > e + 3)
                {
                    Console.WriteLine("您的体重偏胖");
                }
            }


        }
        static void Main(string[] args)
{
            Console.Write("姓名: ");
            Console.ReadLine();
            Console.Write("性别: ");
            string a = Console.ReadLine();
            Console.Write("身高: ");
            double b = double.Parse(Console.ReadLine());
            Console.Write("体重: ");
            double c = double.Parse(Console.ReadLine());
            Program h = new Program();
            h.tizhong(a,b,c);
            Console.ReadLine();
}

5.冒泡排序

        public void paixu(int[] arr)
        {
                    for (int i = 0; i < 10; i++)
            {
                for (int j = i; j < 9; j++)
                {
                    if (arr[i] < arr[j + 1])
                    {
                        int m = 0;
                        m = arr[i];
                        arr[i] = arr[j + 1];
                        arr[j + 1] = m;
                    }
                }
                Console.WriteLine(arr[i]);

            }
        }
       static void Main(string[] args)
{
              int[] arr = new int[10];
            for (int i = 0; i < 10; i++)
            {
                Console.Write("请输入第" + (i + 1) + "个人的分数:");
                arr[i] = int.Parse(Console.ReadLine());
            }
            Program h=new Program();
            h.paixu(arr);
            Console.ReadLine();
}

 

posted @ 2016-04-06 15:41  凌零聆  阅读(152)  评论(0编辑  收藏  举报