日期(today tomorrow)利用struct

#include <stdio.h>

struct date
 {
   int month;
   int day;
   int year;
 };
int main(void)
{
    struct date today,tomorrow; 
    int numberOfDays(struct date d);

 printf("Enter today's date(mm dd yyyy):\n");
 scanf("%i %i %i",&today.month,&today.day,&today.year);
   
 if(today.day!=numberOfDays(today))
 {
   tomorrow.day=today.day+1;
   tomorrow.month=today.month;
   tomorrow.year=today.year;
    }
 else if(today.month!=12)
 {
   tomorrow.day=1;
   tomorrow.month=today.month+1;
   tomorrow.year=today.year;
 }
 else
 {
   tomorrow.day=1;
   tomorrow.month=1;
   tomorrow.year=today.year+1;
 }

 printf("Tomorrow's date is %i  %i  %.2i.\n",tomorrow.month,tomorrow.day,tomorrow.year%100);
 return 0;
 
}

int numberOfDays(struct date d)
{
  int days;
  bool isLeapYear(struct date d);
  const int daysPerMonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
 
  if(isLeapYear(d)==1&&d.month==2)
  {
    days=29;
  }
  else
   days=daysPerMonth[d.month-1];
  return days;
}

bool isLeapYear(struct date d)
{
  bool leapYearFlag;
  if((d.year%4==0&&d.year%100!=0)||d.year%400==0)
  {
    leapYearFlag=1;
  }
  else
 leapYearFlag=0;
  return leapYearFlag;
}
运行结果:
日期(today tomorrow)利用struct_第1张图片

你可能感兴趣的:(日期(today tomorrow)利用struct)