确定母亲节-C语言
                            
                            
                            //確定母親節 
#include <stdio.h>
#include <stdlib.h>
int months[2][13] = {{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },    //非閏年的12個月{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }     //閏年的12個月
};
int isLeap(int year);
int main()
{int base_year = 1900;int base_first_day = 1;int years, days;printf("year: ");scanf("%d/%d", &years);for(int i = base_year; i < years; i++){if(isLeap(i))days += 366;elsedays += 365;}for (int i = 1; i < 5; i++) days += months[isLeap(years)][i];int dayofwork, motherday;dayofwork = days % 7;motherday = 14 - dayofwork;printf("%d年5月%d號是母親節\n", years, motherday);return 0;
} 
int isLeap(int year)    //判斷是否為閏年
{return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
}
                            
                        
                        
                        總結
 
                            
                        - 上一篇: 深入理解Bc和Be
- 下一篇: jQuery动画代码详解
