/*输入一个日期,包括年 月 日 计算并输出这一天是这一年的第几天,要求利用自定义函数计算,用结构指针作为函数参数*/
#include<stdio.h>
struct date{
int year;
int month;
int day;
}d,*p_d = &d;
//日期计算函数原型
int date_calculation(date *p_d);
//日期输入函数原型
void date_input(date *p_d);
void main(){
//输入日期
date_input(p_d);
//计算日期
printf("Your input:%d-%d-%d\n",p_d->year,p_d->month,p_d->day);
printf("It's the %d day of the year!\n",date_calculation(p_d));
}
int date_calculation(date *p_d){
int temp = 0;
for(int i = 1; i < p_d->month;i++){
switch(i){
case 1: temp += 31;break;
case 2: if((p_d->year % 4 == 0 && p_d->year % 100 != 0) || p_d->year % 400 == 0){temp += 29;break;}
else {temp += 28;break;}
case 3: temp += 31;break;
case 4: temp += 30;break;
case 5: temp += 31;break;
case 6: temp += 30;break;
case 7: temp += 31;b
C语言 计算日期是当年的第几天
最新推荐文章于 2025-04-24 03:15:00 发布