c++,编写一个程序,判断某一年是否为闰年。

如题所述

#include <stdio.h>
int main(void)
{
unsigned int year=0;
printf("input a year!");
scanf("%d", &year); if(year % 400==0 || ((year % 100 != 0) && (year % 4 ==0)))
{
printf("是闰年"); }
else
{ printf("不是闰年");
} return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-11-25
#include<iostream>
using namespace std;
int main()
{int year, leap;<br/>cout<<"please enter a year:";<br/>cin>>year;<br/>if(year%4==0&&year%100!=0||year%400==0)<br/> cout<<"year is a leap year"<<endl; <br/> else <br/> cout<<"year is not a leap year"<<endl;<br/> return 0; <br/>}
这个相对来说更简洁一点、、、看得更加清楚点。本回答被网友采纳
第2个回答  2013-10-19
#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;}本回答被网友采纳

相关了解……

你可能感兴趣的内容

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