Created
June 13, 2014 00:48
-
-
Save tshrkmd/d85a90afadaf7f2bf08c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* | |
* 月末を返却 | |
* param yyyy 年 | |
* param mm 月 | |
* return 月末 | |
*/ | |
int get_end_month(int yyyy , int mm) | |
{ | |
int end_days[] = {31,28,31,30,31,30,31,31,30,31,30,31}; // 月末日付を宣言 | |
// うるう年計算 | |
if (mm == 2 && ((yyyy % 4 == 0) && (yyyy % 100 != 0)) || yyyy % 400 == 0) { | |
end_days[mm - 1] = 29; | |
} | |
return end_days[mm - 1]; | |
} | |
/* | |
* | |
* メイン | |
* | |
*/ | |
int main() | |
{ | |
int yyyy = 0; // 年 | |
int mm = 0; // 月 | |
int end_month = 0; // 月末 | |
printf("年を入力してください。 : "); | |
scanf("%d",&yyyy); | |
printf("月を入力してください。 : "); | |
scanf("%d",&mm); | |
end_month = get_end_month( yyyy , mm); | |
printf("月末は : %d\n",end_month); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment