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: