C language example 18:

Source: Internet
Author: User

Question requirements:

Requirement 1: Define a struct variable (including year, month, and day ). Is the day of the current year counted? Pay attention to the leap year issue
Requirement 2: Write a function days to implement the function. The main function transfers year, month, and day to the days function. Number of days after calculation
Returns the output of the main function.

 

# Include <stdio. h> <br/> struct d <br/>{< br/> int year; <br/> int month; <br/> int Day; <br/> int sum; <br/>}; <br/> int days () <br/>{< br/> struct d; <br/> int I; <br/>. sum = 0; <br/> int day_of_month [12] = {31,28, 31,30, 31,30, 31,31, 30,31, 30,31}; <br/> printf ("input year, month, day, format: XXXX-XX-XX/N "); <br/> scanf (" % d-% d ", &. year, &. month, &. day); <br/> If (. year % 4 = 0 &. year % 100! = 0 |. year % 400 = 0) <br/> day_of_month [1] = 29; <br/> for (I = 0; I <. month-1; I ++) <br/>{< br/>. sum + = day_of_month [I]; <br/>}< br/>. sum + =. day; <br/> printf ("% d",. year,. month,. day); <br/> return. SUM; <br/>}< br/> void main () <br/> {<br/> printf ("% d day/N of the Year ", days (); <br/>}

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.