C Language Classic algorithm: Enter a certain date of the month, Judge this day is the first days of the year?
Source: Internet
Author: User
Question: Enter a certain date of the year, Judge this day is the first days of the year.
1. Procedural analysis: Take March 5 as an example, should first add up the first two months, and then add 5 days, that is, the first days of this year, special
Situation, leap year and enter the month is greater than 3 o'clock to consider an additional day.
2. Program Source code:
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);}
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.