天文專家表示,農(nóng)歷雞年是個(gè)閏年,有一個(gè)“閏6月”,共有6個(gè)小月,每月29天和7個(gè)大月,每月30天,一年共有384天。
定義
①、普通年能整除4且不能整除100的為閏年.(如2004年就是閏年,1900年不是閏年)
②、世紀(jì)年能整除400的是閏年.(如2000年是閏年,1900年不是閏年)
③、對于數(shù)值很大的年份,這年如果能被3200整除,并且能被172800整除則是閏年.如172800年是閏年,86400年不是閏年(因?yàn)殡m然能被3200整除,但不能被172800整除)
程序計(jì)算
Ecmascript語言:
1234567 // 判斷指定年份是否為閏年 function isleap(){ var the_year = new Date().getFullYear(); var isleap = the_year % 4 == 0 && the_year % 100 !=0 || the_year % 400 ==0; return isleap; }C#語言:
123456789 /// <summary> /// 判斷指定年份是否為閏年 /// </summary> /// <param name="year">年份</param> /// <returns>返回布爾值true為閏年,反之不是</returns> public static bool isLeapYear(int year) { return ((year % 4 == 0 && year % 100 != 0) ||year%400==0); }Java語言:
12345678910111213import java.util.Scanner;public class LeapYear { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("請輸入年份:"); int year = input.nextInt(); if((year % 4 == 0 && year % 100 != 0) || year % 400 ==0) System.out.print(year + "年是閏年。"); else System.out.print(year + "年不是閏年。"); }}VB語言:
123Public Function isLeapYear(year As Integer) As BooleanisLeapYear = (year Mod 4 = 0 And year Mod 100 <> 0) Or year Mod 400 = 0End FunctionPython 語言:
1234567# -*- coding: cp936 -*-temp = input("輸入年份:")YEAR = int(temp)if (YEAR % 4 == 0 and YEAR % 100 != 0) or YEAR % 400 == 0: print ("閏年")else: print ("非閏年")C++語言:
123456789#include<iostream>int main(){ int year; std::cout<<"請輸入年份:"; std::cin>>year; //輸入待判斷年份,如2008 std::cout<<year<<(((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) == 1 ? "年是閏年" : "年是平年")<<std::endl; return 0;}C語言:
123456789101112#include <stdio.h>int main(void){ int y; printf("請輸入年份,回車結(jié)束 "); scanf("%d",&y); if((y%4==0&&y%100!=0)||y%400==0) printf("%d是閏年 ",y); else printf("%d是平年 ",y); return 0;}MATLAB語言:
12345function lpflag = isleapyear(year)% 判斷是否為閏年% Input -year 年份,數(shù)值% Output -lpflag lpflag = 1,閏年;lpflag = 0,平年lpflag = (~mod(year, 4) && mod(year, 100)) || ~mod(year, 400);Erlang語言:
123456789101112-module(year).-export([isLeap/1]).isLeap(Year) -> if Year rem 400 == 0 -> true; Year rem 100 == 0 -> false; Year rem 4 == 0 -> true; true -> false end.Bash/Shell:
1234567year=$1if [ "$(( $year % 4 ))" == "0" ] && [ "$(( $year % 100 ))" != "0" ] || [ "$(( $year % 400 ))" == "0" ]then echo "leap year"else echo "common year"fi[閏年的定義和程序計(jì)算]