Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- int main(){
- int Week1OfYear=1;
- int year;
- int month;
- int day;
- int c;
- //**********************************************
- //Week1OfYear: week of 1/1 in the year
- //year: year,for dmetermine Week1OfYear
- //month: month,a number for a loop
- //day: day,range of day
- //c: to count "day"
- //**********************************************
- while(1){
- printf("Pleast enter year(2001~2010)\n");
- scanf("%d",&year);
- if(year<2001||year>2010){
- printf("Error!Please enter again!!!\n");
- continue;
- }
- else{
- break;
- }
- }
- //**********************************************
- //input a number year
- //test year if it's not from 2001 to 2010 then
- //continue this loop
- //if it's correct then break this loop
- //**********************************************
- if(year<=2004){
- Week1OfYear = (year-2000)%7;
- }
- else if(year>2004&&year<=2008){
- Week1OfYear = (year-2000+1)%7;
- }
- else{
- Week1OfYear = (year-2000+1+1)%7;
- }
- if(Week1OfYear==0){
- Week1OfYear = 7;
- }
- //**********************************************
- //count week of 1/1
- //if it's leap year then week of 1/1 must +1
- //similarly,if there is to leap year before the
- //then +2
- //**********************************************
- //loop for month
- for(month=1;month<=12;month++){
- //define days for whitch month
- if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
- day = 31;
- }
- else if(month==4||month==6||month==9||month==11){
- day = 30;
- }
- else{
- //count if it's a leap year
- if(year%4==0&&year%100!=0||year%400==0)
- day = 29;
- else
- day = 28;
- }
- //print format of monthly calendar
- printf("------------------------- %d -------------------------\n",month);
- printf("Mon\tTue\tWed\tThur\tFri\tSat\tSun\n");
- for(c=1;c<Week1OfYear;c++){
- printf("\t");
- }
- for(c=1;c<=day;c++){
- printf("%d\t",c);//printf days from 1 to end of month
- if((c+Week1OfYear)%7==1){//while (c+first week of day)'s remainder of 7 is 1 then print newline~
- printf("\n");
- }
- }
- printf("\n\n");//just for typesetting
- if((Week1OfYear+day)%7==0)//if it's Sunday(7 can be divisible,so we need to fix it)
- Week1OfYear=7;
- else
- Week1OfYear = (Week1OfYear+day)%7;//obtain the week of next month's first day
- }//loop,month+1
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment