基于上传视频讲解,使用编程判断某一年是否为闰年的程序代码:,今天小编就来聊一聊关于使用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("请输入正确年份");
}
}
}
}