是闰年吗?
时间: 1ms 内存:128M
描述:
编写函数is_LeapYear实现其参数是否是闰年的判断,如果参数是闰年则返回true,如果不是闰年返回false。
在主函数输入年,调用函数is_LeapYear来进行判断是否是闰年,在main函数中输出结果。
在以下程序的基础上,添加is_LeapYear函数的定义,使程序能够正确执行,提交时,只需要提交is_LeapYear函数的定义代码即可。
#include <iostream>
using namespace std;
bool is_LeapYear(int m); //判断闰年函数的声明
int main()
{
int year;
cin>>year;
if(is_LeapYear(year))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
return 0;
}
输入:
年份
输出:
闰年yes,非闰年no
示例输入:
2015
示例输出:
no
提示:
参考答案(内存最优[1092]):
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a%4==0)
printf("yes");
else
printf("no");
return 0;
}
参考答案(时间最优[0]):
#include <iostream>
using namespace std;
bool is_LeapYear(int m); //判断闰年函数的声明
int main()
{
int year;
cin>>year;
if(is_LeapYear(year))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
return 0;
}
bool is_LeapYear(int m) //判断闰年函数的定义
{
if(m%4==0&&m%100!=0||m%400==0)
return true;
else
return false;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。