Enter a certain date of the year and determine the day of the year

Source: Internet
Author: User
Tags printf

See the full set of "C language problem sets"

Question: Enter a certain day of the month, Judge this day is the first days of the year?

1. Procedural analysis: Take March 5 as an example, the first two months should be added together, and then add 5 days, the first days of the year, special circumstances, leap years and enter a month greater than 3 o'clock to consider an additional day.

2. Program Source code:

#include "stdio.h"
#include "conio.h"
Main ()
{
int day,month,year,sum,leap;
printf ("\nplease input year,month,day\n");
scanf ("%d,%d,%d", &year,&month,&day);
Switch (month)/* First calculates the total number of days before month of the month * *
{
Case 1:sum=0;break;
Case 2:sum=31;break;
Case 3:sum=59;break;
Case 4:sum=90;break;
Case 5:sum=120;break;
Case 6:sum=151;break;
Case 7:sum=181;break;
Case 8:sum=212;break;
Case 9:sum=243;break;
Case 10:sum=273;break;
Case 11:sum=304;break;
Case 12:sum=334;break;
default:printf ("Data Error");
}
Sum=sum+day; /* Plus days of the day * *
if (year%400==0| | (year%4==0&&year%100!=0)) /* Judgment is leap year * *
Leap=1;
Else
Leap=0;
if (leap==1&&month>2)/* If it is a leap year and the month is greater than 2, the total number of days should be plus day *
sum++;
printf ("It is the%dth day.", sum);

}

3.Visual C + + 6.0 debugging pass, as shown in figure:

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.