• 程序语言


    语言

    语言是指程序的命令,都是按照顺序执行的。语言在程序中执行的顺序称之为“控制流”或“执行流”。

    语句是可以镶嵌的,可以是以分号结尾的但行代码,也可以是语块中的但行语句。语句块括在括号{}内,并且可以包含镶嵌块。

    语句分类:

    选择语句:if    else    switch   case

    循环语句: do   for   foreach   while

    跳转语句: break   continue   default   return

    异常语句:try-catch-finally

    一、if  else

    模式:

    ……if (条件)                          if,如果的意思后面判断条件,符合执行下面内容

    ……{内容(这里也可以镶嵌)}

    ……else                               不符合if的条件是,else开始执行

    ……{内容}

    输入三个数,判断三个数的大小从小到大输出打印

                //Console.Write("请输入a=");

                //int x =int.Parse(Console.ReadLine());

                //Console.Write("请输入b=");

                //int y =int.Parse(Console.ReadLine());

                //Console.Write("请输入c=");

                //int z =int.Parse(Console.ReadLine());

                //if (x<y&&x<z)

                //{

                //    if(y<z)

                //        Console.WriteLine("从小到大依次是"+x+y+z);

                //    else if (y>z)

                //        Console.WriteLine("从小到大依次是" + x + z + y);

                //}

                //else if (y < x && y < z)

                //{

                //    if (x < z)

                //        Console.WriteLine("从小到大依次是" + y + x + z);

                //    else

                //        Console.WriteLine("从小到大依次是" + y + z + x);

                //}

                //else

                //{

                //    if (x < y)

                //        Console.WriteLine("从小到大依次是" + z + x + y);

                //    else

                //        Console.WriteLine("从小到大依次是" + z + y + x);

                //}

                //Console.ReadLine();

                //Console.Write("请输入姓名");

                //string name = Console.ReadLine();

                //Console.Write("请输入成绩");

                //double a = double.Parse(Console.ReadLine());

                //if (a <= 100 && a >= 50)

                //{

                //    if (a == 100)

                //        Console.WriteLine("恭喜你" + name + ",满分通过!");

                //    else if (a < 100 && a >= 80)

                //        Console.WriteLine("" + name + ",你很优秀,继续保持!");

                //    else if (a < 80 && a >= 60)

                //        Console.WriteLine("" + name + ",成绩良好");

                //    else if (a < 60)

                //        Console.WriteLine("" + name + ",就差一点点,下次一定要至少及格!");

                //}

                //else

                //{

                //    Console.WriteLine("" + name + ",你是笨蛋么?");

                //}

                //Console.ReadLine();

                //有一组函数:y = x (x<1);y = 2x -1  (1<=x<10); y = 3x-11  (x>=10)。括号内是x的满足条件。

                //实现功能,随意输入一个x值,输出y的值。

                //Console.Write("请输入x");

                //double x =double.Parse(Console.ReadLine());

                //if(x<1)

                //{

                //    double y = x;

                //    Console.WriteLine("y=" + y + "");

                //}

                //else if (x<10&&x>=1)  

                //{

                //    double y = 2 * x - 1;

                //Console.WriteLine("y=" + y + "");

                //}

                //else if (x>=10)

                //{

                //    double y = 3 * x - 11;

                //    Console.WriteLine("y=" + y + "");

                //}

                //Console.ReadLine();

                //输入整数a和b,若a2+b2大于100,则输出a2+b2百位以上数字,否则输出两数之和

                //Console.Write("请输入数字a");

                //int a = int.Parse(Console.ReadLine());

                //Console.Write("请输入b");

                //int b = int.Parse(Console.ReadLine());

                //int c = a * a + b * b;

                //if (c > 100)

                //{

                //    int d = c - 100;

                //    Console.WriteLine("y=" +d + "");

                //}

                //else

                //{

                //    int e = a + b;

                //    Console.WriteLine(e);

                //}

                //Console.ReadLine();

                //相亲过程:你有房子么?你有钱么?你有能力么?

                //【结婚吧】【先买房子在结婚】【先赚钱再买房子再结婚】都没有【拜拜~~】

                            //Console.Write("你有房子吗?");

                //string a = Console.ReadLine();

                //if (a == "有")

                //{

                //    Console.WriteLine("结婚吧");

                //}

                //else

                //{

                //Console.Write("你有钱么?");

                //    string b = Console.ReadLine();

                //    if(b=="有")

                //    {

                //    Console.WriteLine("先买房子在结婚");

                //    }

                //    else

                //    {

                //      Console.Write("你有能力么?");

                //    string c = Console.ReadLine();

                //    if(c=="有")

                //    {

                //     Console.WriteLine("先赚钱再买房子再结婚");

                //    }

                //      else

                //{

                //Console.WriteLine("拜拜~~");

                //}

                //    }

                //}

                //Console.ReadLine();

    二元一次方程求解

    △=b2-4ac,若小于0无解等于零一个解;大于0两个解

                //Console.WriteLine("求二元一次方程a*x*x+b*x+c=o的解");

                //Console.Write("请输入a");

                //int a = int.Parse(Console.ReadLine());

                //Console.Write("请输入b");

                //int b = int.Parse(Console.ReadLine());

                //Console.Write("请输入c");

                //int c = int.Parse(Console.ReadLine());

                //int d = b * b - 4 * a * c;

                //if (d < 0)

                //{

                //    Console.WriteLine("方乘没有解!");

                //}

                //else

                //{

                //    double x1 = (-b + Math.Sqrt(d)) / (2 * a);

                //    double x2 = (-b - Math.Sqrt(d)) / (2 * a);

                //    if (d == 0)

                //    {

                //        Console.WriteLine("方乘有一个解!");

                //        Console.WriteLine("x1=x2=" + x1);

                //    }

                //    else

                //    {

                //        Console.WriteLine("方乘有两个解!");

                //        Console.WriteLine("x1=" + x1);

                //        Console.WriteLine("x2="+x2);

                //    }

                //}

                //Console.ReadLine();

    输入身高体重,判断是否正常

    男性:体重-身高+100在±3之间

    女性:体重-身高+110在±3之间

                // Console.Write("请输入性别:");

                // string sex = Console.ReadLine();

                // Console.Write("请输入身高:");

                //double h = double.Parse( Console.ReadLine());

                // Console.Write("请输入体重:");

                // double w = double.Parse(Console.ReadLine());

                // if (sex == "男")

                // {

                //     double a = w - h + 100;

                //     if (a < 3 && a > -3)

                //     {

                //         Console.WriteLine("您的体重是正常的");

                //     }

                //     else

                //     {

                //         Console.WriteLine("您的体重是不正常的");

                //     }

                // }

                // else

                // {

                //     double b = w - h + 110;

                //     if (b < 3 && b < -3)

                //     {

                //         Console.WriteLine("您的体重是正常的");

                //     }

                //     else

                //     {

                //         Console.WriteLine("您的体重是不正常的");

                //     }

                // }

                // Console.ReadLine();

    输入日期,判断对错。

                Console.Write("请输入年份:");

                int n = int.Parse(Console.ReadLine());

                if (n < 9999 && n > 0)

                {

                    Console.Write("请输入月份:");

                    int m = int.Parse(Console.ReadLine());

                    if (m < 13 && m > 0)

                    {

                        Console.Write("请输入日期:");

                        int d = int.Parse(Console.ReadLine());

                        if (d < 32 && d > 0)

                        {

                            if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)

                            {

                                Console.WriteLine("您输入的日期是:" + n + m + d);

                            }

                            else

                            {

                                if (m == 4 || m == 6 || m == 9 || m == 11 && d < 31 && d > 0)

                                {

                                    Console.WriteLine("您输入的日期是:" + n + m + d);

                                }

                                else

                                {

                                    if (d < 29 && d > 0 && m == 2)

                                    {

                                        Console.WriteLine("您输入的日期是:" + n + m + d);

                                    }

                                    else

                                    {

                                        if (d < 30 && d > 0 && m == 2 && n % 4 == 0 && n % 100 != 0 || n % 400 == 0)

                                        {

                                            Console.WriteLine("您输入的日期是:" + n + m + d);

                                        }

                                        else

                                        {

                                            Console.WriteLine("您输入的日期有误!");

                                        }

                                    }

                                }

                            }

                        }

                        else

                        {

                            Console.WriteLine("您输入的日期有误!");

                        }

                    }

                    else

                    {

                        Console.WriteLine("您输入的月份有误!");

                    }

                }

                else

                {

                    Console.WriteLine("您输入的年份有误!");

                }

                Console.ReadLine();

  • 相关阅读:
    蜘蛛禁止访问文件
    基于PhalApi的Smarty拓展 (视图层的应用)
    MySQL数据库存表情
    查看PHP版本等相关信息
    读取数据库表信息
    nginx简介
    Redis发布订阅
    Redis持久化
    Redis主从复制
    Redis的Java客户端Jedis
  • 原文地址:https://www.cnblogs.com/light3857/p/5599478.html
Copyright © 2020-2023  润新知