C language-Enter the year, month, and day to figure out the day of the year

Source: Internet
Author: User

/*note:your Choice is C IDE*/#include"stdio.h"voidMain () {intY,m,d;//year, month, day    intcr,ds=0I//CR: The variable that determines whether it is a leap year, is 1, no 0;ds: The sum of the days; I is a loop variable    Charrun[ A] = { to, in, to, -, to, -, to, to, -, to, -, to};//number of days per month for leap years    Charping[ A] = { to, -, to, -, to, -, to, to, -, to, -, to};//common year number of days of the monthprintf"Please enter the year you want to inquire: \ n"); scanf ("%d", &y);//Enter YearCR = y%4==0&&y% -!=0|| y% -==0;//determines whether a leap year, is 1, no is 0     Do{printf ("Please enter month: \ n"); scanf ("%d", &m);//Enter Month        if(m<0|| M> A){//determine if there are any input errorsprintf"input wrong, please re-enter! \ n");} } while(m<0|| M> A);//wrong re-entry     Do{printf ("Please enter the date: \ n"); scanf ("%d", &d);//Enter Date        if(d> to){//determine if you have entered a number greater than 31stprintf"input wrong, please re-enter! (Up to 31 days in one months) \ n"); }Else if(d>run[m-1]&&cr==1)//determines whether a number of days in a leap year is within the maximum number of days in the month{printf ("%d months up to%d days, please re-enter! \ n", m,run[m-1]); }Else if(d>ping[m-1]&&cr==0)//determine whether common year days are within the maximum number of days of the month{printf ("%d months up to%d days, please re-enter! \ n", m,ping[m-1]); }    } while((d>run[m-1]&&cr==1)|| (d>ping[m-1]&&cr==0)); if(CR = =1){//calculate the total number of days in a leap year         for(i=0; i<m-1; i++) {DS+=Run[i]; }    }Else{//calculates the total number of days in the year for a common year         for(i=0; i<m-1; i++) {DS+=Ping[i]; } DS+ = D;//plus the number of days in the monthprintf"%d%d months%d days is the%d day of the year! ", Y,m,d,ds); }      }

C language-Enter the year, month, and day to figure out the day of the 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.