逻辑判断题。首先,来理一下思路:
1.输入年份,如果不能整除4,则不是闰年;
2.若能整除4,则分为两种情况:如果还能被100整除且能够整除400,则是闰年;若不能,则不是。
Y表示是闰年,N表示是平年。
#include <iostream>
#include <string>
using namespace std;
char judge(int a)
{
char flag;
if (a%4==0)
{
if(a%100==0)
{
if (a%400==0)
{
flag='Y';
}
else
flag='N';
}
else
flag='Y';
}
else
flag='N';
return flag;
}
int main()
{
cout<<"输入年份"<<endl;
int year;
cin>>year;
char res=judge(year);
cout<<res<<endl;
return 0;
}
输入年份
1990
N
[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-u2yfeefz.xuo" 1>"/tmp/Microsoft-MIEngine-Out-vv54qbmx.nll"
按任意键继续...