首页 > 试题广场 >

判断闰年

[编程题]判断闰年
  • 热度指数:22757 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解

判断一个整数n是否是闰年



输入描述:
输入一个整数n (


输出描述:
是闰年输出"yes" 否则输出"no"
示例1

输入

2000

输出

yes
示例2

输入

1900

输出

no
#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n % 400 == 0 || n % 4 == 0 && n % 100 != 0) cout << "yes" << endl;
    else cout << "no" << endl;
}

发表于 2022-02-26 14:07:32 回复(2)
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >>a;
    if(a%4==0 && a%100!=0){
        cout<<"yes"<<endl;
           
    }
    else if(a%400==0){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
    return 0;
}
发表于 2024-11-25 18:48:51 回复(0)
//能被4整除但不能被100整除的年份是闰年,能被400整除的年份也是闰年。
//2024年是闰年,因为它可以被4整除,但不能被100整除。
//1900年不是闰年,因为它可以被100整除,但不能被400整除。
//1600年是闰年,可以被4整除,也能被100整除,但它同时也能被400整除。

#include <stdio.h>

int main()
{
    int a = 0;
    scanf("%d", &a);
    
    if(a % 400 == 0)
    {
        printf("yes\n");
    }
    else
    {
        if(a % 4 == 0 && a % 100 != 0)
        {
            printf("yes\n");
        }
        else {
            printf("no\n");
        }
    }
    return 0;
}

发表于 2024-01-28 21:56:09 回复(0)
#include <stdio.h>
//闰年的判断方法可以简化为:
// 1. 能被4整除但不能被100整除的年份是闰年
// 2. 能被400整除的年份也是闰年
int main() {
    int n=0;
    scanf("%d",&n);
    if((n%4==0&&n%100!=0)||(n%400==0))
    {
        printf("yes");
    }
    else {
    {
        printf("no");
    }
    }
    return 0;
}

发表于 2024-01-13 10:15:36 回复(0)
n=int(input())
if (n%4==0 and n%100!=0)&nbs***bsp;n%400==0:
    print('yes')
else:
    print('no')    

发表于 2023-01-18 09:44:35 回复(0)
year= int(input())
if year % 400 == 0:
    print('yes')
elif (year % 4 == 0) and (year % 100 != 0):
    print('yes')
else:
    print('no')
发表于 2022-03-17 19:16:16 回复(1)
a = int(input())
if (a%4==0 and a%100!=0)&nbs***bsp;(a%400==0):
    print("yes")
else:
    print("no")

发表于 2025-04-28 10:37:27 回复(0)
a=int(input())
if (a%4==0 and a%100!=0) or (a%400==0):
    print('yes')
else:
    print('no')

闰年分为普通闰年和世纪闰年,具体判断规则如下:
  • 普通闰年:公历年份是 4 的倍数,且不是 100 的倍数的年份为普通闰年。例如 2004 年能被 4 整除且 不能被 100 整除,所以 2004 年是普通闰年。
  • 世纪闰年:公历年份是 400 的倍数的年份为世纪闰年。例如 2000 年能被 400 整除,所以 2000 年是世纪闰年;而 1900 年不能被 400 整除,虽然它能被 4 整除,但它同时能被 100 整除,所以 1900 年不是闰年。

发表于 2025-02-14 17:31:40 回复(0)
#include <stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    if ((n%4==0&&n%100!=0)||n%400==0)
    {
        printf("yes");
    }
    else
    {
        printf("no");
    }
    return 0;
}
发表于 2024-11-25 20:59:56 回复(0)
#include <stdio.h>

int main() {
    int a;
    scanf("%d", &a);
    if ((a % 4 == 0 ) && (a % 100 != 0) || (a % 400 == 0 ) ) {
        printf("yes\n");
    } else {
        printf("no\n");
    }
    return 0;
}
#include <stdio.h>

int main() {
    int a;
    scanf("%d", &a);
    if ((a % 4 == 0 ) && (a % 100 != 0) || (a % 400 == 0 ) ) {
        printf("yes\n");
    } else {
        printf("no\n");
    }
    return 0;
}

发表于 2024-10-03 21:10:31 回复(0)
#include <stdio.h>

int main() {
    int n;
    scanf("%d",&n);
    if(1<=n&&n<=2018)
    {
        if((n%4==0&&n%100!=0)||n%400==0)
        {
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
    }
    return 0;
}

发表于 2024-09-24 20:38:21 回复(0)
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n%100!=0)
    {
        if(n%4==0)
        {
            printf("yes");
        }
         else{
        printf("no");
}
    }
    else if(n%400==0)
        {
            printf("yes");
        }
        else {
            printf("no");
        }
}
   
   
发表于 2024-06-08 20:05:36 回复(0)
int main()
{
	int year = 0;
	scanf("%d", &year);
	//1900年是平年 
	//普通年,润年, 世纪年
	if ((year % 4 == 0  && year % 100 != 0) || year % 400 == 0)
		printf("yes\n");
	else
		printf("no\n");
	return 0;
}

发表于 2024-04-03 21:43:24 回复(0)
#include <stdio.h>

int main() {
   int year=0;
   scanf("%d",&year);
   printf((year%4==0&&year%100!=0||year%400==0)?"yes":"no");
    return 0;
}
编辑于 2024-03-10 16:27:15 回复(0)
a = int(input())
if (a%4==0 and a%100!=0)&nbs***bsp;(a%400==0):
    print("yes")
else:
    print("no")

发表于 2024-02-04 13:03:35 回复(0)
#include <stdio.h>

int main() {
    int a;
    scanf("%d", &a);
    if(a%100==0){
        printf("%s", a%400==0?"yes":"no");
    }
    else{
        printf("%s", a%4==0?"yes":"no");
    }
    return 0;
}
发表于 2024-01-13 12:06:38 回复(0)
package main

import (
    "fmt"
)

func main() {
    var x,l,r int32
    fmt.Scan(&x,&l,&r)
    if l<=x && r>=x {
        fmt.Println("true")
    } else {
        fmt.Print("false")
    }
}
编辑于 2023-12-17 10:08:32 回复(0)
#include <stdio.h>

int main() {
    int year = 0;
    //可以整除4,但不能除100,可以整除400,4年一闰,百年不闰,四百年一闰
    scanf("%d",&year);
    if(year%4==0 && year%100!=0 || year%400==0)
    {
        printf("yes");
    }
    else
    {
        printf("no");
    }
    return 0;
}
编辑于 2023-12-05 17:34:18 回复(0)
#include <stdio.h>

int main()
{
    int n = 0;
    scanf("%d",&n);

    if(n % 4 == 0 && n % 100 !=0  || n % 400 == 0)
        {
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }

    return 0;
}
发表于 2023-11-04 20:59:08 回复(0)
#include <stdio.h>

int main()
{
    int n =0;
    scanf("%d",&n);
    if(n>=1&&n<=2018)
    {
        if(n%4==0&&n%100!=0)
        {
            printf("yes");
        }
        else if(n%400==0)
        {
            printf("yes");
        }
        else
        {
            printf("no");
        }
    }
    return 0;
}
发表于 2023-11-04 20:19:38 回复(0)

问题信息

上传者:牛客301599号
难度:
62条回答 2962浏览

热门推荐

通过挑战的用户

查看代码
判断闰年