//自己做的
//判断闰年还是平年
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("输入的年份不正确!日期有假");
//}