用计算机程序怎么算闰年,闰年的定义和程序计算

天文专家表示,农历鸡年是个闰年,有一个“闰6月”,共有6个小月,每月29天和7个大月,每月30天,一年共有384天。

定义

①、普通年能整除4且不能整除100的为闰年.(如2004年就是闰年,1900年不是闰年)

②、世纪年能整除400的是闰年.(如2000年是闰年,1900年不是闰年)

③、对于数值很大的年份,这年如果能被3200整除,并且能被172800整除则是闰年.如172800年是闰年,86400年不是闰年(因为虽然能被3200整除,但不能被172800整除)

程序计算

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        ///         /// 判断指定年份是否为闰年        ///         /// 年份        /// 返回布尔值true为闰年,反之不是        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 Function

Python 语言:

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#includeint main(){    int year;    std::cout<>year;             //输入待判断年份,如2008    std::cout<

C语言:

123456789101112#include int main(void){    int y;    printf("请输入年份,回车结束 ");    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 年份,数值% 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

[闰年的定义和程序计算]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值