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>