/*************************************** ************************
C Language
AUTHOR: liuyongshui
**************************************** ***********************/
/*
Question 15: Define a struct variable (including year, month, and day), input the birthdays of two people, and find out how many days they differ.
*/
# Include <stdio. h>
Struct date
{
Int year;
Int month;
Int day;
};
Int checkyear (int n); // statement of the original function, used to check whether it is a leap year or a flat year. If it is 'distinct', 1 is returned; otherwise, 0 is returned.
Const int Day_Of_Month [] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31 }; // The number of days of each month on a yearly basis
Int main ()
{
Int I;
Int j;
Int flag;
Int sum_day [2] = {0, 0 };
Struct date person_birthday [2];
Printf ("Enter the date of birth of two people \ n ");
For (I = 0; I <2; I ++)
{
Printf ("the date of birth of person % d:", I + 1); // print the person
Scanf ("% d", & person_birthday [I]. year,
& Amp; person_birthday [I]. month,
& Person_birthday [I]. day );
}
For (I = 0; I <2; I ++)
{
Flag = checkyear (person_birthday [I]. year );
If (flag) // if the flag is distinct, 1 is returned, and 0 is returned.
{
Sum_day [I] ++;
}
For (j = 0; j <person_birthday [I]. month; j ++)
{
Sum_day [I] + = Day_Of_Month [j];
}
Sum_day [I] + = person_birthday [I]. day;
}
For (I = 0; I <2; I ++)
{
Printf ("output % d person's birthday % d day \ n", I + 1, sum_day [I]);
}
If (sum_day [0]> sum_day [1])
{
Printf ("% d days \ n", sum_day [0]-sum_day [1]);
}
Else
{
Printf ("% d days \ n", sum_day [1]-sum_day [0]);
}
Return 0;
}
// Function Definition
Int checkyear (int n)
{
If (n % 4 = 0 & n % 100! = 0) | n % 400 = 0) // It is a leap year.
Return 0;
Else // year
Return 0;
}