首页 > 代码库 > 2014-12-11 C# if语句 题目

2014-12-11 C# if语句 题目

//判断是否是闰年

            int b = int.Parse(Console.ReadLine());
            if (b % 4 == 0 && b % 100 != 0)
            {
                Console.WriteLine("是闰年");
            }
            else if (b % 400 == 0)
            {
                Console.WriteLine("是闰年");
            }
            else
                Console.WriteLine("不是闰年");
                    Console.ReadLine();

 

//控制台分别录入年月日,判断是否是一个正确的日期

Console.WriteLine("请输入年");
                string year = Console.ReadLine();
                int x = int.Parse(year);
                Console.WriteLine("请输入月");
                string month = Console.ReadLine();
                int y = int.Parse(month);
                Console.WriteLine("请输入日");
                string day = Console.ReadLine();
                int z = int.Parse(day);
           
                    if ((y == 1) || (y == 3) || (y == 5) || (y == 7) || (y == 8) || (y == 10) || (y == 12))
                    {
                        if ((z >= 1) && (z <= 31))
                        {
                            Console.WriteLine("输入正确");
                        }
                        else
                            Console.WriteLine("请输入正确的日");
                    }
                    else if (y == 2)
                    {
                        if ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0))
                        {
                            if ((z >= 1) && (z <= 29))
                            {
                                Console.WriteLine("输入正确");
                            }
                                Console.WriteLine("请输入正确的日");
                        }
                        else if (x % 4 != 0)
                        {
                            if ((z >= 1) && (z <= 28))
                            {
                                Console.WriteLine("输入正确");
                            }
                            Console.WriteLine("请输入正确的日");
                        }
                    }
                    else if((y==4)||(y==6)||(y==9)||(y==11))
                    {
                        if ((z >= 1) && (z <= 30))
                        {
                            Console.WriteLine("输入正确");
                        }
                        else
                            Console.WriteLine("请输入正确的日");
                    }
                    else
                        Console.WriteLine("请输入正确的月");
                 Console.ReadLine();

 

//输入一个1-100之内的数,判断是否跟7有关

 int a = int.Parse(Console.ReadLine());
              if(a>=1 && a<=100)
              {
                  if((a%7==0)||(a%10==7)||(a/10==7))
                  {
                      Console.WriteLine("与7有关");
                  }
                  else
                      Console.WriteLine("与7无关");

 

//输入身高、体重、性别,判断是否是标准体重,男性标准=(身高-100)+-3,女性标准=(身高-110)+-3

Console.WriteLine("请输入身高");
                int hight = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入体重");
                int weight = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入性别");
                string sex = Console.ReadLine();
                if (sex == "男")
                {
                    int a = hight - 100;
                    if (weight > (a + 3))
                    {
                        Console.WriteLine("不是标准体重,偏胖");
                    }
                    else if (weight <= (a + 3) && weight >= (a - 3))
                    {
                        Console.WriteLine("是标准体重");
                    }
                    else
                        Console.WriteLine("不是标准体重,偏瘦");
                    Console.ReadLine();
                }
                else if (sex == "女")
                {
                    int a = hight - 110;
                    if (weight > (a + 3))
                    {
                        Console.WriteLine("不是标准体重,偏胖");
                    }
                    else if (weight <= (a + 3) && weight >= (a - 3))
                    {
                        Console.WriteLine("是标准体重");
                    }
                    else
                        Console.WriteLine("不是标准体重,偏瘦");
                }
                else
                    Console.WriteLine("请输入正确的性别");
                Console.ReadLine();

 

//输入一元二次方程的三个参数,a,b,c,判断是否为一元二次方程,并求解

Console.WriteLine("请输入a");
            int a = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入b");
            int b = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入c");
            int c = int.Parse(Console.ReadLine());
            int r = (b * b - 4 * a * c);
            if (r > 0)
            {
                double x1 = (Math.Sqrt(r) - b) / (2 * a);
                double x2 = (-b - Math.Sqrt(r)) / (2 * a);
                Console.WriteLine("方程有两个不相等的解:x1={0},x2={1}",x1,x2);
            }
            else if (r == 0)
            {
                double x = (-b) / (2 * a);
                Console.WriteLine("方程有一个解");
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine("方程没有实数解");
            }
            Console.ReadLine();

 

//与电脑猜拳

Console.WriteLine("猜拳:请输入剪刀-0、石头-1或布-2");
            int human=int.Parse(Console.ReadLine());
            Random r = new Random();
            int computer = r.Next(3);
            if((human-computer==1)||(computer-human==2))
            {
                Console.WriteLine("电脑出拳={0},你出拳={1}+你赢了",computer,human);
            }
            else if((computer-human==2)||(human-computer==1))
            {
                Console.WriteLine("电脑出拳={0},你出拳={1}+你输了",computer,human);
            }
            else
                Console.WriteLine("平局");
            Console.WriteLine();
            Console.WriteLine();

 

//switch case

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

switch(i)

{

case 1:

    console.WriteLine("星期一");

    break;

 

case 2:

 

    console.WriteLine("星期二");

 

    break;

 

case 3:

 

    console.WriteLine("星期三");

 

    break;

 

 

case 4:

 

    console.WriteLine("星期四");

 

    break;

 

case 5:

 

    console.WriteLine("星期五");

 

    break;

default:

    console.WriteLine("你输入的可能不正确");

    break;

 

//计算一年的第几天

 

Console.WriteLine("请输入年");
            int year = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入月");
            int month = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入日");
            int day = int.Parse(Console.ReadLine());
            int sum=0;
            if ((year % 4 == 0 && year % 100 != 0)||(year%400==0))
            switch(month)
            {
                case 1:
                    sum=day;
                    break;
                case 2:
                    sum=31+day;
                    break;
                case 3:
                    sum=31+29+day;
                        break;
                case 4:
                    sum=31+29+31+day;
                    break;
                case 5:
                    sum=31+29+31+30+day;
                    break;
                case 6:
                    sum=31+29+31+30+31+day;
                    break;
                case 7:
                    sum=31+29+31+30+31+30+day;
                    break;

 

                   ………………                   

                    default;
                    Console.ReadLine();
                    break;

 

2014-12-11 C# if语句 题目