使用c語言判斷某一年為閏年?基于上傳視頻講解,使用編程判斷某一年是否為閏年的程序代碼:,今天小編就來聊一聊關于使用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("請輸入正确年份");
}
}
}
}
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!