作业帮 > 综合 > 作业

用switch语句判断润平年.

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/08/05 15:43:21
用switch语句判断润平年.
用switch语句判断润平年.
if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0)
{
Console.WriteLine("请输入月份");
int y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入多少日");
int r = Convert.ToInt32(Console.ReadLine());
int d = 0;
switch (b)
{
case 1: y = 0; break;
case 2: y = 31; break;
case 3: y = 60; break;
case 4: y = 91; break;
case 5: y = 121; break;
case 6: y = 152; break;
case 7: y = 182; break;
case 8: y = 213; break;
case 9: y = 244; break;
case 10: y = 274; break;
case 11: y = 305; break;
case 12: y = 335; break;
}
//年==n 月==y 日==r 上面那个是求天的 不懂追问
再问: Console.WriteLine("请输入月份"); int y = Convert.ToInt32(Console.ReadLine()); 这个是什么意思呀,不好意思我是大一的才开始学习程序~~~不懂~~~~~~~~求解
再答: 用switch判断平润年是超级麻烦的 我给你的那个 是用switch判断大小月 其实判断润平年很简单 四年一润百年不润四百年又润 n % 4 == 0 && n % 100 != 0 || n % 400 == 0你应该懂得 如果满足这个条件就是闰年 else :平年 欢迎追问!!
再问: 就是输入一个年份和月份输出该月的日子数〜〜〜〜
再答: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ex03 { class Program { public static bool IsLeapYear(int year) { return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; } static void Main(string[] args) { int[] a = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int[] b = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; Console.Write("请输入年月日(yyyy年xx月zz日): "); string str = Console.ReadLine(); string[] strs = str.Split(' '); int year = Convert.ToInt32(strs[0]); int month = Convert.ToInt32(strs[1]); int date = Convert.ToInt32(strs[2]); int[] days = IsLeapYear(year) ? b : a; int sum = 0; for (int i = 0; i < month - 1; i++) { sum += days[i]; } sum += date; Console.WriteLine("{0}年{1}月{2}日是这一年的第{3}天", year, month, date, sum); } } }
再问: 麻烦你啦〜谢谢〜