(C)定义一个结构体包括年月日,编写一个函数days,计算该日期在本年中是第几天。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct dt
{
	int year;
int month;
int day;
};
int days(struct dt);
void main()
{
int countday;
struct dt date;
printf("请输入年月日:\n");
scanf_s("%d,%d,%d",&date.year,&date.month,&date.day);
countday=days(date);
printf("日期%d%2d%2d为%d的第%d天",date.year,date.month,date.day,date.year,countday);
system("pause");
}
int days(struct dt date)
{
	int result=0;
	int year=date.year,month=date.month,day=date.day;
	switch(month-1)
	{
	case 12: result+=31;
	case 11: result+=30;
	case 10: result+=31;
	case 9: result+=30;
	case 8: result+=31;
	case 7: result+=31;
	case 6: result+=30;
	case 5: result+=31;
	case 4: result+=30;
	case 3: result+=31;
	case 2: {
			if(year%400==0||year%4==0&&year%100!=0)
				result+=28;
			else result+=29;
			}
	case 1: result+=31;
	}
	result+=day;//加上对应的月份的天数
	return result;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值