如何判断闰年和平年的方法有哪些?

2025-10-04 09:43:18

1、普通闰年:公历年份是4的倍数的,且不是100的倍数,为普通闰年(如2004年、2020年就是闰年)。

世纪闰年:公历年份是整百数的,必须是400的倍数才是世纪闰年(如1900年不是世纪闰年,2000年是世纪闰年)。

如何判断闰年和平年的方法有哪些?

2、对于数值很大的年份,这年如果能整除3200,并且能整除172800则是闰年。如172800年是闰年,86400年不是闰年(因为虽然能整除3200,但不能整除172800)(此按一回归年365天5h48'45.5''计算)。

1、口诀1:4年1闰,400年97闰,3200年(97*8-1)闰,86400年(27*(97*8-1)+1)闰(20926闰)

口诀2:4年1闰,128年31闰,86400年(675*31+1)闰(20926闰)

四年一闰,百年不闰,四百年再闰。例如:2000年是闰年,2100年则是平年。

如何判断闰年和平年的方法有哪些?

1、WPS表格:

=OR(AND(MOD(YEAR(单元格),4)=0,MOD(YEAR(单元格),100)<>0),MOD(YEAR(单元格),400)=0)

Ecmascript语言:

如何判断闰年和平年的方法有哪些?

2、Ecmascript语言:

// 判断指定年份是否为闰年

       function isleap(){

           var the_year = new Date().getFullYear();

           var isleap = (the_year % 4 == 0 && the_year % 100 !=0) || (the_year % 400 ==0 && year % 3200 != 0) || year % 172800 == 0;

           return isleap;

       }

如何判断闰年和平年的方法有哪些?

3、C#语言:

        /// <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 && year % 3200 != 0) || year % 172800 == 0);

        }

4、Java语言:

import 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 && year % 3200 != 0) || year % 172800 == 0)

            System.out.print(year + "年是闰年。");

        else 

            System.out.print(year + "年不是闰年。");

    }

}

如何判断闰年和平年的方法有哪些?

5、VB语言:

Private Sub Command1_Click()

Dim a As Integer

a = InputBox("请输入待判断年份")

If (a Mod 4 = 0 And a Mod 100 <> 0) Or (a Mod 400 = 0 And a Mod 3200 <> 0) Or (a Mod 172800 = 0) Then

  MsgBox "是闰年!"

Else

  MsgBox "不是闰年!"

  End If

End Sub

6、Python 语言:

# -*- coding: cp936 -*-

temp = input("输入年份:")

YEAR = int(temp)

if (YEAR % 4 == 0 and YEAR % 100 != 0) or (YEAR % 400 == 0 and YEAR % 3200 != 0) or year % 172800 == 0

:    

    print ("闰年")

else:

    print ("非闰年")

7、C++语言:

#include<iostream>

int main()

{

    int year;

    std::cout<<"请输入年份:";

    std::cin>>year;             //输入待判断年份,如2008

    std::cout<<year<<(((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0 && year % 3200 != 0) || year % 172800 == 0

)

) == 1 ? "年是闰年" : "年是平年")<<std::endl;

    return 0;

}

8、scheme语言:

(define (闰年? 年份)

  (define (整除? x y)

    (= 0 (mod x y)))

  (cond ((or 

      (and (整除? 年份 4)

           (not (整除? 年份 100)))

      (and (整除? 年份 400)

           (not (整除? 年份 3200)))

      (整除? 年份 172800))

     #t)

    (else #f)))

9、C语言:

#include <stdio.h>

int main(void)

{

    int y;

    printf("请输入年份,回车结束\n");

    scanf("%d",&y);

    if((y%4==0&&y%100!=0)||(y%400==0&&y%3200!=0)||y%172800==0)

        printf("%d是闰年\n",y);

    else

        printf("%d是平年\n",y);

    return 0;

}

10、MATLAB语言:

function lpflag = isleapyear(year)

% 判断是否为闰年

% Input  -year 年份,数值

% Output -lpflag lpflag = 1,闰年;lpflag = 0,平年

lpflag = (~mod(year, 4) && mod(year, 100)) || (~mod(year, 400) && mod(year, 3200)) || ~mod(year, 172800)

;

11、Erlang语言:

-module(year).

-export([isLeap/1]).

isLeap(Year) ->

    if Year rem 3200 /= 0 and Year rem 400 == 0 -> true;

    Year rem 100 /= 0 and Year rem 4 == 0 -> true;

        Year rem 172800 == 0 ->true;

    true ->

        false

    end.

12、Bash/Shell:

year=$1

if [ "$(( $year % 4 ))" == "0" ] && [ "$(( $year % 100 ))" != "0" ] || [ "$(( $year % 400 ))" == "0" ] && [ "$(( $year % 3200 ))" != "0" ] || [ "$(( $year % 172800 ))" == "0" ] 

then

    echo "leap year"

else

    echo "common year"

fi

13、易语言:

.局部变量 年份, 整数型

' 是否是闰年

.如果真 ((年份 % 4 = 0 且 年份 % 100 ≠ 0) 或 (年份 % 400 = 0 且 年份 % 3200 ≠ 0) 或 年份 % 172800 = 0

)

    信息框 (“是闰年!”, 0, , )

14、Go语言:

// IsLeapYear 检查传入的年份是否是闰年

func IsLeapYear(year int) bool {

    if (year%4 == 0 && year%100 != 0) || (year%400 == 0 && year%3200 != 0) || year%172800 == 0

 {

        return true

    }

    return false

}

15、JavaScript语言:

function isLeapYear(year){

 if((year/4==Math.floor(year/4)&&year/100!=Math.floor(year/100))||(year/400==Math.floor(year/400)&&year/3200!=Math.floor(year/3200))||year/172800==Math.floor(year/172800)){

  return true

 }

 return false

如何判断闰年和平年的方法有哪些?

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢