The day ordinal of a year

Source: Internet
Author: User

#include <stdio.h> #include <stdlib.h>/* enter month and date, the day of the year that the output is dated. Year greater than 1900*/int monthdays[12] = {N, a, A, a, a, a, a, a, a, a, a, a};int isgoodyear (int year); int Isgoodmont H (int month), int isgoodday (int year,int month,int day), int isleapyear (int), int dayofyear (int, int month, Int. Day int main () {int year, month, Day;while (Fflush (stdin), scanf ("%d%d%d", &year, &month, &day)! = EOF) {if (Isgoo Dyear (year) && Isgoodmonth (month) && Isgoodday (year, month, day)//Determine if the input is legitimate printf ("%d\n", DayOfYear ( (month, day)); elseprintf ("Please input a right date.\n");} System ("pause"); return 0;} int dayofyear (int, int, month, int day) {//The first days of the year int total = 0;for (int i = 0; i < month-1; ++i) Total + = monthdays[ I];total + = Day;if (Isleapyear (year) && (Month > 2)) Total++;return total; int isleapyear (int year) {if ((year% 4 = = 0) && (year% 100! = 0)) | | (Year% 400 = = 0)) return 1;elsereturn 0;} int isgoodyear (int year) {if (yeaR >= 1900) return 1;elsereturn 0;} int isgoodmonth (int month) {if ((month >= 1) && (month <=)) return 1;elsereturn 0;} int Isgoodday (int year, Int. month, int day) {switch (month) {Case 2:if (isleapyear (year)) if (day >= 1) && lt;=) return 1;else if ((Day >= 1) && (day <=)) return 1;elsereturn 0;case 4:case 6:case 9:case 11:if ( (Day >= 1) && (day <=)) return 1;elsereturn 0;case 1:case 3:case 5:case 7:case 8:case 10:case 12:if ( >= 1) && (day <=)) return to 1;elsereturn 0;default:printf ("Month error in day judge.\n"); return 0;}}

  

The day ordinal of a year

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.