C language: the day of a year, month, or year

Source: Internet
Author: User

C language: the day of a year, month, or year

Looking at this title, it is actually quite simple to implement this function. You can easily implement this function by using the switch statement in C language with the condition of a leap year or a year, and some logic, in the Linux kernel, there is an interface for determining the year of a leap. After porting It, I write it into a macro for the number of days of computing to call the function to see if it can be implemented and run the Code:

# Include <stdio. h> # include <stdlib. h> enum {zero = 0, NUM_TWO = 2, NUM_THR = 13, tw_e = 28, tw_n = 29, st_z = 30, st_o = 31,}; # define isleap (y) (y) % 4) = 0 & (y) % 100 )! = 0 | (y) % 400) = 0) // judge whether it is a leap year or a normal year static int years [NUM_TWO] [NUM_THR] = {zero, st_o, tw_e, st_o, st_z, st_o, \ st_z, st_o, st_o, st_z, st_o, clerk, st_o}, {zero, st_o, clerk, st_o, st_z, st_o, \ st_z, st_o, st_o, st_z, st_o, st_z, st_o }}; static int Count (int year, int month, int day); int main () {int year, month, day, m; int day_num; printf ("please input (year-month-day) \ n"); scanf ("% d-% d", & year, & month, & day); // enter day_n in the preceding format Um = Count (year, month, day); printf ("day_num: % d \ n", day_num); return 0;} static int Count (int year, int month, int day) {int flag = 0; static int I; if (isleap (year) // judge whether it is a leap year or a flat year flag = 1; // set the flag to one for (I = 0; I <month; I ++) return = "" day = "" pre = ""> running result for a leap year: <p> </p> <p> we can see that today is July 22, 54th, and July! The time has passed so fast that two months have passed. I hope your colleagues will cherish the time and learn more technical knowledge!  </P>  </p> </month; I ++)> </stdlib. h> </stdio. h>

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.