Guest User

Untitled

a guest
Jun 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main(){
  5. int Week1OfYear=1;
  6. int year;
  7. int month;
  8. int day;
  9. int c;
  10. //**********************************************
  11. //Week1OfYear: week of 1/1 in the year
  12. //year: year,for dmetermine Week1OfYear
  13. //month: month,a number for a loop
  14. //day: day,range of day
  15. //c: to count "day"
  16. //**********************************************
  17. while(1){
  18. printf("Pleast enter year(2001~2010)\n");
  19. scanf("%d",&year);
  20. if(year<2001||year>2010){
  21. printf("Error!Please enter again!!!\n");
  22. continue;
  23. }
  24. else{
  25. break;
  26. }
  27. }
  28. //**********************************************
  29. //input a number year
  30. //test year if it's not from 2001 to 2010 then
  31. //continue this loop
  32. //if it's correct then break this loop
  33. //**********************************************
  34. if(year<=2004){
  35. Week1OfYear = (year-2000)%7;
  36. }
  37. else if(year>2004&&year<=2008){
  38. Week1OfYear = (year-2000+1)%7;
  39. }
  40. else{
  41. Week1OfYear = (year-2000+1+1)%7;
  42. }
  43.  
  44. if(Week1OfYear==0){
  45. Week1OfYear = 7;
  46. }
  47. //**********************************************
  48. //count week of 1/1
  49. //if it's leap year then week of 1/1 must +1
  50. //similarly,if there is to leap year before the
  51. //then +2
  52. //**********************************************
  53.  
  54.  
  55. //loop for month
  56. for(month=1;month<=12;month++){
  57. //define days for whitch month
  58. if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
  59. day = 31;
  60. }
  61. else if(month==4||month==6||month==9||month==11){
  62. day = 30;
  63. }
  64. else{
  65. //count if it's a leap year
  66. if(year%4==0&&year%100!=0||year%400==0)
  67. day = 29;
  68. else
  69. day = 28;
  70. }
  71.  
  72.  
  73. //print format of monthly calendar
  74. printf("------------------------- %d -------------------------\n",month);
  75. printf("Mon\tTue\tWed\tThur\tFri\tSat\tSun\n");
  76. for(c=1;c<Week1OfYear;c++){
  77. printf("\t");
  78. }
  79. for(c=1;c<=day;c++){
  80. printf("%d\t",c);//printf days from 1 to end of month
  81. if((c+Week1OfYear)%7==1){//while (c+first week of day)'s remainder of 7 is 1 then print newline~
  82. printf("\n");
  83. }
  84. }
  85. printf("\n\n");//just for typesetting
  86.  
  87.  
  88. if((Week1OfYear+day)%7==0)//if it's Sunday(7 can be divisible,so we need to fix it)
  89. Week1OfYear=7;
  90. else
  91. Week1OfYear = (Week1OfYear+day)%7;//obtain the week of next month's first day
  92. }//loop,month+1
  93. system("PAUSE");
  94. return 0;
  95. }
Add Comment
Please, Sign In to add comment