c++,编写一个程序,判断某一年是否为闰年。
3个回答
2013-10-19
展开全部
#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;
}
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;
}
推荐于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/>}
这个相对来说更简洁一点、、、看得更加清楚点。
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/>}
这个相对来说更简洁一点、、、看得更加清楚点。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
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;}
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;}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询