使用c语言判断某一年为闰年(编程判断某一年是否为闰年)
基于上传视频讲解,使用编程判断某一年是否为闰年的程序代码:,今天小编就来聊一聊关于使用c语言判断某一年为闰年?接下来我们就一起去研究一下吧!
![使用c语言判断某一年为闰年(编程判断某一年是否为闰年)](http://img.studyofnet.com/upimg/980472145.jpg)
使用c语言判断某一年为闰年
基于上传视频讲解,使用编程判断某一年是否为闰年的程序代码:
代码1:使用if语句(If...else...)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace leapYear
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ushort nyear;
if(ushort.TryParse(textBox1.Text,out nyear))
{
if ((nyear % 4 == 0 && nyear % 100 != 0) || nyear % 400 == 0)
{
textBox2.Text = textBox1.Text "是闰年";
}
else
{
textBox2.Text = textBox1.Text "不是闰年";
}
}
else
{
MessageBox.Show("请输入正确年份");
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace leapYear
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ushort nyear;
if(ushort.TryParse(textBox1.Text,out nyear))
{
//使用条件运算符(?:)
textBox2.Text=(nyear % 4 == 0 && nyear % 100 != 0) || nyear % 400 == 0 ? textBox1.Text "是闰年" : textBox1.Text "不是闰年";
}
else
{
MessageBox.Show("请输入正确年份");
}
}
}
}
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com