//结构体变量(年、月、日),计算该日在本年是第几天,注意闰年问题#include<stdio.h>//定义结构体structdate{int year;int month;int day;};//函数1判断是否是闰年intfunc1(int year){int leap =0;if((year %400==0)||((year %4==0)&&(year %100!=0)))
leap =1;//leap=1表示该年是闰年return leap;}//函数2计算并输出结果voidfunc2(int year,int month,int day){//每月天数数组int dayy[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//result中存放结果int result =0;//引用函数1int leap =func1(year);printf("leap=%d\n", leap);if(leap ==1)//闰年,2月28号后的天数要加1{if((month >2)||((month ==2)&&(day >28))){for(int i =1; i < month; i++){
result = result+dayy[i];}
result = result +day +1;}}else{for(int i =1; i < month; i++){
result = result + dayy[i];}
result = result + day;}printf("the result is %d\n", result);}//主函数intmain(){//定义结构体变量structdate days;//输入年月日printf("Please enter the date to be calculated (year, month, day)>>\n");scanf_s("%d%d%d",&days.year,&days.month,&days.day);//调用函数输出结果func2(days.year, days.month, days.day);return0;}