zoukankan      html  css  js  c++  java
  • 闰年、平年

    //自己做的
                //判断闰年还是平年
                Console.WriteLine("请输入年份");
                int a = Convert.ToInt32(Console.ReadLine());
    
                if (a > 0 && a <= 9999)
                {
                    if (a % 100 == 0)//能被100整除并且能被400整除的是闰年
                    {
                        if (a % 400 == 0)
                        {
                            Console.WriteLine("该年是闰年");
                        }
                        else
                        {
                            Console.WriteLine("该年是平年");
                        }
                    }
                    else if (a % 4 == 0)
                    {
                        Console.WriteLine("该年是闰年");
                    }
                    else
                    {
                        Console.WriteLine("该年是平年");
                    }
    
                }
                else
                {
                    Console.WriteLine("年份输入错误");
                }
     //自己做的
                //判断该年是闰年还是平年,并且判断该年中的月份和日期
    
                Console.WriteLine("请输入年份");
                int a = Convert.ToInt32(Console.ReadLine());
                int r;//定义r,当r=0的时候是闰年,r=1的时候是平年
                if (a > 0 && a <= 9999)
                {
                    if (a % 100 == 0)//能被100整除并且能被400整除的是闰年,如果不能被100整除,但是能被4整除的是闰年
                    {
                        if (a % 400 == 0)
                        {
                            r=0;
                            Console.WriteLine("该年是闰年");
                        }
                        else
                        {
                            r=1;
                            Console.WriteLine("该年是平年");
                        }
                    }
                    else if (a % 4 == 0)
                    {
                        r=0;
                        Console.WriteLine("该年是闰年");
                    }
                    else
                    {
                        r=1;
                        Console.WriteLine("该年是平年");
                    }
                    //判断月份
                    Console.WriteLine("请输入月份");
                    int b=Convert.ToInt32(Console.ReadLine());
    
                    Console.WriteLine("请输入天数");
                    int c1 = Convert.ToInt32(Console.ReadLine());
    
                    if (b > 0 && b <= 12)
                    {
                        if (b != 2)//2月份除外的其他月份
                        {
                            if (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12)
                            {
                                Console.WriteLine("本月有31天");
                               
                                if (c1 > 0 && c1 <= 31)
                                {
                                    Console.WriteLine("本天是本月的第{0}天",c1);
                                }
                                else
                                {
                                Console.WriteLine("输入的日期有错误");
                                }
                            }
                            else
                            {
                                Console.WriteLine("本月有30天");
                                if (c1 > 0 && c1 <= 30)
                                {
                                    Console.WriteLine("本天是本月的第{0}天", c1);
                                }
                                else
                                {
                                    Console.WriteLine("输入的日期有错误");
                                }
                            }
                        }
                        else if (b==2)//2月份
                        {
                            if (r == 0)
                            {
                                Console.WriteLine("本月有28天");
                                if (c1 > 0 && c1 <= 28)
                                {
                                    Console.WriteLine("本天是该月的第{0}天", c1);
                                }
                                else
                                {
                                    Console.WriteLine("输入的日期有错误");
                                }
                            }
                            else
                            {
                                Console.WriteLine("本月有29天");
                                if (c1 > 0 && c1 <= 29)
                                {
                                    Console.WriteLine("本天是本月的第{0}天", c1);
                                }
                                else
                                {
                                    Console.WriteLine("输入的日期有错误");
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("输入的月份有错误");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("年份输入错误");
                }
    //老师做的
                //判断该年是闰年还是平年,并且判断该年中的月份和日期
                //Console.WriteLine("请输入年份:");
                //int nian = Convert.ToInt32(Console.ReadLine());
    
                //Console.WriteLine("请输入月份:");
                //int yue = Convert.ToInt32(Console.ReadLine());
    
                //Console.WriteLine("请输入日期:");
                //int ri = Convert.ToInt32(Console.ReadLine());
    
                //int r = 0; //r=0代表平年 r=1代表闰年
    
                //if (nian > 0 && nian < 9999)
                //{
                //    //判断闰年还是平年
                //    if (nian % 100 == 0)
                //    {
                //        if (nian % 400 == 0)
                //        {
                //            r = 1;
                //            Console.WriteLine("该年是闰年");
                //        }
                //        else
                //        {
                //            Console.WriteLine("该年是平年");
                //        }
                //    }
                //    else
                //    {
                //        if (nian % 4 == 0)
                //        {
                //            r = 1;
                //            Console.WriteLine("该年是闰年");
                //        }
                //        else
                //        {
                //            Console.WriteLine("该年是平年");
                //        }
                //    }
    
                //    //判断月份
                //    if (yue >= 1 && yue <= 12)
                //    {
                //        //判断日期是否合法
                //        if (yue == 1 || yue == 3 || yue == 5 || yue == 7 || yue == 8 || yue == 10 || yue == 12)
                //        {
                //            if (ri <= 31 && ri > 0)
                //            {
                //                Console.WriteLine("输入的日期正确!");
                //            }
                //            else
                //            {
                //                Console.WriteLine("输入的日期不正确!");
                //            }
                //        }
                //        else if (yue == 4 || yue == 6 || yue == 9 || yue == 11)
                //        {
                //            if (ri <= 30 && ri > 0)
                //            {
                //                Console.WriteLine("输入的日期正确!");
                //            }
                //            else
                //            {
                //                Console.WriteLine("输入的日期不正确!");
                //            }
                //        }
                //        else
                //        {
                //            if (r == 1)
                //            {
                //                if (ri > 0 && ri <= 29)
                //                {
                //                    Console.WriteLine("输入的日期正确!");
                //                }
                //                else
                //                {
                //                    Console.WriteLine("输入的日期不正确!");
                //                }
                //            }
                //            else
                //            {
                //                if (ri > 0 && ri <= 28)
                //                {
                //                    Console.WriteLine("输入的日期正确!");
                //                }
                //                else
                //                {
                //                    Console.WriteLine("输入的日期不正确!");
                //                }
                //            }
                //        }
    
                //    }
                //    else
                //    {
                //        Console.WriteLine("输入的月份不正确,日期有假!");
                //    }
    
    
                //}
                //else
                //{
                //    Console.WriteLine("输入的年份不正确!日期有假");
                //}
  • 相关阅读:
    使用log4cplus时遇到的链接错误:无法解析的外部符号 "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,
    linux中free命令内存分析
    ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
    error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“0”不匹配值“2
    创建预编译头 Debug 正常 Release Link Error:预编译头已存在,使用第一个 PCH
    C++定义字符数组
    客户端数据持久化解决方案: localStorage
    转:JavaScript函数式编程(三)
    转: JavaScript函数式编程(二)
    转:JavaScript函数式编程(一)
  • 原文地址:https://www.cnblogs.com/SJP666/p/4646658.html
Copyright © 2011-2022 走看看