#include <iostream.h>
#include <stdio.h>
int Days[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool CheckDate(int iYear, int iMonth, int iDay);
int main(void)
{
int iYear, iMonth, iDay;
cout < < "Year: ";
cin> > iYear;
cout < < "Month: ";
cin> > iMonth;
cout < < "Day: ";
cin> > iDay;
cout < <CheckDate(iYear, iMonth, iDay);
cout < <endl;
return 0;
}
bool CheckDate(int iYear, int iMonth, int iDay)
{
if(iMonth <1 || iMonth> 12) return false;
bool b_IsLeapYear=false;
if(iYear%4==0)
{
b_IsLeapYear=true;
if(!(iYear%100==0 && iYear%400==0)) b_IsLeapYear=false;
}
if(b_IsLeapYear) Days[1]=29;
else Days[1]=28;
if(iDay <0 || iDay> Days[iMonth-1]) return false;
return true;
}
判断日期合法性
最新推荐文章于 2022-05-19 17:50:04 发布