要求:(1)判断是否是闰年(2)给定某年的某一天能判断是星期几(3)给定某月的某个星期几能判断出是几月几号(4)给定某一年能打印出全年的日历

热心网友

基本思路就是利用time。h中的结构和变量进行日期的转换与计算,这里涉及到一个结构变量tm和一个time_t变量(实际为长整型)。(1)判断是否为闰年很简单,就是年份能被4整除而且不能被400整除的就是闰年。(2)给出一段示范代码int iYear, iMonth, iDay;printf("please input the year(=1900), the month(1-12), the date(1-31): ");scanf("%d %d %d", &iYear, &iMonth, &iDay);struct tm struct_time = {0};struct_ _year = iYear - 1900;struct_ _mon = iMonth - 1;struct_ _mday = iDay;time_t ttime;ttime = mktime(&struct_time); //转换struct_time = *localtime(&ttime);printf("%d\n", struct_ _wday); //输出星期几,0为周日printf("%s\n", asctime(&struct_time)); //以字符串形式输出日期理解了之后,(3)和(4)也就轻而易举了。。

热心网友

C语言的书上就有