【C/C++】判断一个数是不是闰年

来源:互联网 发布:怎么找网络棋牌漏洞 编辑:程序博客网 时间:2024/05/22 03:42

生活中,我们都知道如何判断某一年是不是闰年


我们都知道,能被4整除并且不能被100整除的是闰年

能被400整除的也是闰年


根据算法,我们写出下面程序


#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#include<stdlib.h>int IsLeapYear(int y){return (y%100!=0&&y%4==0)||(y%400 == 0);}int main(){int year = 0;printf("请输入需要查询的年份:>");scanf("%d", &year);int check = IsLeapYear(year);if (0 == check)printf("%d年不是闰年\n",year);elseprintf("%d年是闰年\n",year);system("pause");return 0;}

在该程序中,我们封装了IsLeapYear()

该函数的返回值是


返回1,是闰年

返回0,不是闰年




1 0
原创粉丝点击