C# 2 闰年平年 老狼几点了

 

 作业

第一题 老狼几点了。凌晨,上午,下午,晚上。

wps8E9F.tmpwps8EB0.tmpwps8EB1.tmpwps8EC2.tmpwps8EC3.tmp 

 static void Main (string[] args)

     

        {

            //输入

            Console.Write("老狼老狼几点了?");

            string s = Console.ReadLine();

            int hour = Convert.ToInt32(s);

 

            if (0 <= hour && hour < 6)

            {

                Console.WriteLine("凌晨" + hour + "点了");

            }

            else if (hour >= 6 && hour < 12)

            {

                Console.WriteLine("上午" + hour + "点了");

            }

            else if (hour > 12 && hour < 18)

            {

                hour = hour - 12;

                Console.WriteLine("下午" + hour + "点了");

            }

            else if (hour >= 18 && hour < 24)

            {

                hour = hour - 12;

                Console.WriteLine("晚上" + hour + "点了");

            }

            else

            {

                Console.WriteLine("不可识别的时间!");

            }

 

 

        }

 

//第二题 判断一元二次方程根的情况。   

wps8ED3.tmpwps8EF4.tmpwps8F04.tmpwps8F15.tmp

    

static void Main (string[] args)    

    {             int a, b, c;            //输入;             Console.Write("请输入系数a");      

      a = Convert.ToInt32(Console.ReadLine());       

     Console.Write("请输入系数b");       

     b = Convert.ToInt32(Console.ReadLine());         

   Console.Write("请输入系数c");     

       c = Convert.ToInt32(Console.ReadLine());

            //运算输出       

     if (a == 0)        

    {             

   Console.WriteLine("不是一元二次方程");     

       }        

    else        

    {            

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

         if (d > 0)           

     {                

    Console.WriteLine("两个不等实根");         

       }              

  else if (d == 0)      

          {                 

   Console.WriteLine("两个相等实根");      

          }               

else               

{                

    Console.WriteLine("无实根");     

           }         

   }    

    }   

}

}

 

 

//第三题   输入一个年份判断是闰年,还是平年。  

wps8F25.tmpwps8F36.tmp

      static void ccc(string[] args)     

   {       

     int year;           

//输入          

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

    year = Convert.ToInt32(Console.ReadLine());

  //运算           

//能被400整除;或能被4整除,但不能被100整除。       

     if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))        

    {             

   Console.WriteLine("是闰年");       

     }             else        

    {             

   Console.WriteLine("是平年");        

    }      

  } 

   }

}

第四题 称体重。

男人的标准体重是:体重(kg)=身高(cm)-100

女人的标准体重是:体重(kg)=身高(cm)-110

上下浮动3公斤属正常

要求输入性别、身高和体重,输出正常,偏胖,偏瘦

wps8F47.tmpwps8F67.tmp 

  class Class3

    {

        static void Main(string[] args)

        {

            string sex;

            int weight, height;

            //输入

            Console.Write("性别(男,女):");

            sex = Console.ReadLine();

            Console.Write("身高(CM):");

            height = Convert.ToInt32(Console.ReadLine());

            Console.Write("体重(KG):");

            weight = Convert.ToInt32(Console.ReadLine());

 

            int biaoZhunTiZhong=0;

            //运算输出

            if(sex == "男")

            {

                //求标准体重

                biaoZhunTiZhong = height - 100;

            }

            else if(sex == "女")

            {

                //求标准体重

                biaoZhunTiZhong = height - 110;

            }

            else

            {

                Console.WriteLine("性别不正确");

            }

 

            //求体重差

            int tiZhongCha = weight - biaoZhunTiZhong;

            if (tiZhongCha >= -3 && tiZhongCha <= 3)

            {

                Console.WriteLine("体重正常,继续保持!");

            }

            else if (tiZhongCha < -3)

            {

                Console.WriteLine("偏瘦,注意增加营养");

            }

            else

            {

                Console.WriteLine("偏胖,注意运动减肥");

            }

        }

    }

}

 

 

第五题 输入年、月、日,判断是否是个正确的日期。

 class Class4

    {

        static void Main(string[] args)

        {

            int year = 0, month = 0, day = 0;

            //输入

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

            year = Convert.ToInt32(Console.ReadLine());

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

            month = Convert.ToInt32(Console.ReadLine());

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

            day = Convert.ToInt32(Console.ReadLine());

 

            //判断运算输出

            //判断年份是否正确

            if(year < 0 || year>9999)

            {

                Console.WriteLine("年输入不正确");

            }

            else

            {

                Console.WriteLine("年正确");

            }

 

            //判断月份是否正确

            if (month < 1 || month > 12)

            {

                Console.WriteLine("月输入不正确");

            }

            else

            {

                Console.WriteLine("月正确");

            }

 

            //判断天是否正确

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

            {

                if(day < 1 || day>31)

                {

                    Console.WriteLine("天输入错误,大月份最多是31天");

                }

                else

                {

                    Console.WriteLine("天正确");

                }

            }

            else if (month == 4 || month == 6 || month == 9 || month == 11)

            {

                if (day < 1 || day > 30)

                {

                    Console.WriteLine("天输入错误,小月份最多是30天");

                }

                else

                {

                    Console.WriteLine("天正确");

                }

            }

            else if(month == 2)

            {

                //闰年与平年的判断

                if(year%400==0 || year%4==0&&year%100!=0)

                {

                    //闰年

                    if (day < 1 || day > 29)

                    {

                        Console.WriteLine("天输入错误,闰年2月份最多是29天");

                    }

                    else

                    {

                        Console.WriteLine("天正确");

                    }

                }

                else

                {

                    //平年

                    if (day < 1 || day > 28)

                    {

                        Console.WriteLine("天输入错误,平年2月份最多是28天");

                    }

                    else

                    {

                        Console.WriteLine("天正确");

                    }

                }

            }

        }

    }

}

 

 

原文地址:https://www.cnblogs.com/981971554nb/p/4309673.html