c语言源代码(计算明天的日期)

2022-07-11 20:10:15   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《c语言源代码(计算明天的日期)》,欢迎阅读!
源代码,明天,日期,语言,计算
#include "stdio.h"

struct date{ //声明结构体 int year; int month; int day; };

int numberofday(struct date d);//判断这一天是否为这个月的最后一天的函数原型声明 int isleap(struct date d); //判断是否为闰年的函数原型声明 int main() {

struct date today, tomorry; //定义结构体变量 printf("请输入今天的日期( ):");

scanf("%d %d %d",&today.year,&today.month,&today.day); if(today.day !=numberofday(today)) { tomorry.year=today.year; tomorry.month=today.month; tomorry.day=today.day +1; }

else if(today.month==12) { tomorry.year=today.year+1; tomorry.month=1; tomorry.day=1; } else{ tomorry.year=today.year; tomorry.month=today.month+1; tomorry.day=1; }

printf("明天的日期是:%d %d %d",tomorry.year,tomorry.month,tomorry.day); return 0; }

int numberofday(struct date d) { int day; int isday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; //定义12个月的数组. if(d.month==2&&(isleap(d))) { day=isday[d.month]+1; } else { day=isday[d.month];


} return day; }

int isleap(struct date d) { if((d.year%4==0&&d.year%100!=0)||d.year%400==0) return 1; else return 0; }




本文来源:https://www.wddqxz.cn/bd6f5ae5ba1aa8114531d9a1.html