闰年判断 写一个程序,能够判断从键盘上输入的年份是否是一个闰年

如题所述

判断闰年的标准是:

1、能整除4且不能整除100 。

2、能整除400。

C代码如下:

#include<iostream>
using namespace std;
int main()
{
bool leapyear(int year);
int year;
bool leap;
cout<<"请输入年份:";
cin>>year;
getchar();
leap =leapyear(year);
if (leap)
cout<<year<<"is";
else
cout <<year <<"is not";
cout<<"a leap year"<<endl;
getchar();
return 0;
}bool leapyear(int year){
     bool leap;
if (year%4==0)
{ if(year%100==0)
{ if(year%400==0)
 leap=true;
 else
leap=false;}
else
leap=true;
}
else
    leap=false;return leap;}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-07-06
我想问问,

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网