Question 14: define a struct variable (including year, month, and day). Enter the year, month, and day to calculate and output the day of the year.

Source: Internet
Author: User

/*************************************** ************************
C Language

AUTHOR: liuyongshui
 
**************************************** ***********************/
/*
Question 14: define a struct variable (including year, month, and day). Enter the year, month, and day to calculate and output the day of the year.
*/

# 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 flag;
Int sum_day = 0;

Struct date birthday;
Printf ("Enter your date of birth :");
Scanf ("% d", & birthday. year, & birthday. month, & birthday. day );

Flag = checkyear (birthday. year );
If (flag) // if the flag is distinct, 1 is returned, and 0 is returned.
{
Sum_day ++;
}

For (I = 0; I <birthday. month; I ++)
{
Sum_day + = Day_Of_Month [I];
}

Sum_day + = birthday. day;

Printf ("after scientific computation, you were born on day % d of % d. \ N ", birthday. year, sum_day );

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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.