#include "stdio.h"
typedef struct{
int day;
int year;
}indate;
typedef struct{
int day;
int month;
int year;
}opdate;
bool Isleap(int d);
void caltime(indate *dd, opdate *dt);
int main(){
indate ti = { 0, 0 };
opdate time = { 0, 0, 0 };
//Time(&ti);
do{
printf("input the year and the day's number (year num)\n");
scanf("%d %d", &ti.year, &ti.day);
} while (ti.day<1 || (ti.day>366 && Isleap(ti.year))||(ti.day>365 && !Isleap(ti.year)));
caltime(&ti, &time);
printf("The date is %d/%d/%d (d/m/y)\n", time.day, time.month, time.year);
}
bool Isleap(int d){
int answer;
if ((d % 4 == 0 && d % 100 != 0) || d % 400 == 0){
answer = 1;
}
else{
answer = 0;
}
return answer;
}
void caltime(indate *dd, opdate *dt){
int mnth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int yer = dd->year;
int idx = 0;
int mnday = 0;
if (Isleap(yer)){
mnth[1]=29;
}
while (mnday < dd->day){
mnday += mnth[idx];
idx++;
}
dt->year = dd->year;
dt->month = idx;
dt->day = mnth[idx - 1] - (mnday - dd->day);
}
输入年和第几天算日期
最新推荐文章于 2023-08-29 23:43:47 发布