うるう年判定関数を利用して、その月の月末日を取得しましょう。
When you would like to know whether it is leap year or not,
you would like to know the last day of month.
Get the day.
関連記事:うるう年判定【C言語】
#define TRUE 0 #define FALSE -1 // is leap or not int IsLeapYear(int year) { if (((year % 4 == 0) && (year % 100 != 0)) || year % 400 == 0) { return TRUE; } else { return FALSE; } } // get the last day of month int GetLastDay(int year, int month) { int leap; int lmdays[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int mdays[] = {31,28,31,30,31,30,31,31,30,31,30,31}; leap = IsLeapYear(year); // leap year if (leap == TRUE) { return lmdays[month - 1]; // no_leap year } else { return mdays[month - 1]; } }
0 コメント:
コメントを投稿