为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

嵌入式判断闰年平年

2017-10-11 5页 doc 17KB 17阅读

用户头像

is_998870

暂无简介

举报
嵌入式判断闰年平年嵌入式判断闰年平年 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace 例4_6 { public partial class Form1 : Form { public Form1() { Initiali...
嵌入式判断闰年平年
嵌入式判断闰年平年 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace 例4_6 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //******************************************************************** // 【计算】按钮的单击事件代码 //******************************************************************** private void btnCount_Click(object sender, EventArgs e) { int y, m, d, sum; y = int.Parse(txtInputYear.Text); m = int.Parse(txtInputMonth.Text); d = int.Parse(txtInputDay.Text); if (y < 1 || y > 9999) { txtResult.Text = "请输入正确的年号!"; txtInputYear.Text = ""; // 清除错误的年号 txtInputYear.Focus(); // 输入年号的文本框获得焦点,等待重新输入 goto count; // 年号错误转到程序尾部,即结束应用程序 } else if (m < 1 || m > 12) { txtResult.Text = "请输入正确的月份!"; txtInputMonth.Text = ""; txtInputMonth.Focus(); goto count; } else switch(m) { case 2: if ((y % 100 != 0 && y % 4 == 0) || (y % 400 == 0)) { if (d < 1 || d > 29) { txtResult.Text = "闰年二月29天,请输入正确的日 期!"; txtInputDay.Text = ""; txtInputDay.Focus(); goto count; } } else { if (d < 1 || d > 28) { txtResult.Text = "平年二月28天,请输入正确的日 期!"; txtInputDay.Text = ""; txtInputDay.Focus(); goto count; } } break; case 4: case 6: case 9: case 11: if (d < 1 || d > 30) { txtResult.Text = "小月为30天,请输入正确的日期!"; txtInputDay.Text = ""; txtInputDay.Focus(); goto count; } break; default: if (d < 1 || d > 31) { txtResult.Text = "大月为31天,请输入正确的日期!"; txtInputDay.Text = ""; txtInputDay.Focus(); goto count; } break; } if (m == 1 || m == 2) sum = (m - 1) * 31 + d; else { switch (m) { case 9: case 11: sum = (m - 1) * 30 + d - 2 + m / 2 + 1; break; default: sum = (m - 1) * 30 + d - 2 + m / 2; break; } if ((y % 100 != 0 && y % 4 == 0) || (y % 400 == 0)) sum = sum + 1; } txtResult.Text = y + "年" + m + "月" + d + "日为" + y + "年的第" + sum + "天!"; // 在程序尾部设置一条空语句,并添加一个标签,当输入错误时跳转至此 count: ; } } }
/
本文档为【嵌入式判断闰年平年】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
热门搜索

历史搜索

    清空历史搜索