给定某个年,月,日,计算出这一天是属于该年的第几天。要求写出计算闰年的函数和计算日期的函数。

来源:百度知道 编辑:UC知道 时间:2024/06/02 08:24:36

int totalday(int year,int month,int day)//计算天数函数
{
int leap(int);//声明
int judge;
judge=leap(year);//调用
int total_day=0;
month-=1;
switcg(month)
{
case 11:total_day+=30;
case 10:total_day+=31;
case 9:total_day+=30;
case 8:total_day+=31;
case 7:total_day+=31;
case 6:total_day+=30;
case 5:total_day+=31;
case 4:total_day+=30;
case 3:total_day+=31;
case 2:judge?total_day+=29:total_day+=28;
case 1:total_day+=31;
case 0:total_day+=day;break;
default :break;
}
return total_day;
}

int leap(int year)//判断闰年函数
{
if(year%4==0&year%100!=0||year%400==0)
return 1;
else
return 0;
}

这是我的,有判断日期是否合法,是否闰年和计算日期的函数
#include <stdio.h>

int isLeap(int year){
int res = 0;
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
res = 1;
}
return res;
}

int monthDays(int year,