Guest User

Untitled

a guest
Jan 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. /* HW1 Onyedi Anyansi
  2. Calendar */
  3.  
  4. #include <stdio.h>
  5. #include <math.h>
  6.  
  7. //2000 starts on saturday
  8. int findstartday(int year)
  9. {
  10.  
  11. int i = 0;
  12. int yc = 2006;
  13. if (year > 2006)
  14. {
  15. while (year > yc)
  16. {
  17. if(yc%4 == 0)
  18. {
  19. if(yc % 100 == 0)
  20. {
  21. if (yc % 400 == 0) i = i + 2;
  22. else i++;
  23. }
  24. else i = i + 2;
  25. }
  26. else i++;
  27. yc++;
  28. }
  29. i = i % 7;
  30. }
  31. if (year < 2006)
  32. {
  33. while (year < yc)
  34. {
  35. if((yc-1) % 4 == 0)
  36. {
  37. if((yc-1) % 100 == 0)
  38. {
  39. if ((yc-1) % 400 == 0) i = i + 2;
  40. else i++;
  41. }
  42. else i = i + 2;
  43. }
  44. else i++;
  45. yc--;
  46. }
  47. i = i % 7;
  48. if (i == 6) i = 1;
  49. else if (i == 5) i = 2;
  50. else if (i == 4) i = 3;
  51. else if (i == 3) i = 4;
  52. else if (i == 2) i = 5;
  53. else if (i == 1) i = 6;
  54. }
  55.  
  56. return i;
  57. }
  58.  
  59. int printMonthName(int year, int month)
  60. {
  61. switch(month)
  62. {
  63. case 1:
  64. printf("January %d \n\n",year);
  65. break;
  66. case 2:
  67. printf("February %d \n\n",year);
  68. break;
  69. case 3:
  70. printf("March %d \n\n",year);
  71. break;
  72. case 4:
  73. printf("April %d \n\n",year);
  74. break;
  75. case 5:
  76. printf("May %d \n\n",year);
  77. break;
  78. case 6:
  79. printf("June %d \n\n",year);
  80. break;
  81. case 7:
  82. printf("July %d \n\n",year);
  83. break;
  84. case 8:
  85. printf("August %d \n\n",year);
  86. break;
  87. case 9:
  88. printf("September %d \n\n",year);
  89. break;
  90. case 10:
  91. printf("October %d \n\n",year);
  92. break;
  93. case 11:
  94. printf("November %d \n\n",year);
  95. break;
  96. case 12:
  97. printf("December %d \n\n",year);
  98. break;
  99.  
  100. }
  101. if (month <= 7)
  102. {
  103. if (month % 2 == 1) return 31;
  104. else if (month == 2)
  105. {
  106. if(year % 4 == 0)
  107. {
  108. if(year % 100 == 0)
  109. {
  110. if (year % 400 == 0) return 29;
  111. else return 28;
  112. }
  113. else return 29;
  114. }
  115. else return 28;
  116. }
  117. else return 30;
  118. }
  119. else
  120. {
  121. if (month % 2 == 1) return 30;
  122. else return 31;
  123. }
  124. }
  125.  
  126. int printMonth(int year, int month, int day)
  127. {
  128. int days;
  129. int i = 0;
  130. int count = 1;
  131.  
  132. days = printMonthName (year, month);
  133. printf("Sun Mon Tue Wed Thu Fri Sat\n");
  134. while (i < day)
  135. {
  136. //if (day == 0) break;
  137. printf(" ");
  138. i++;
  139. }
  140. while (count <= days)
  141. {
  142. if (i >= 6)
  143. {
  144. printf("%d \n", count);
  145. i = -1;
  146. }
  147. else printf("%d ", count);
  148. i++;
  149. count++;
  150. }
  151. return i;
  152. }
  153.  
  154. int printCalendar(int year, int day)
  155. {
  156. int i = 1;
  157. int sday;
  158. sday = day;
  159.  
  160. printf("\n \n!!Calendar for %d!! \n\n",year);
  161. for (i = 1; i <= 12; i++)
  162. {
  163. sday = printMonth(year, i, sday);
  164. printf("\n \n");
  165. }
  166. return 0;
  167. }
  168.  
  169. int main(void)
  170. {
  171. int year, i, lol;
  172. printf("Enter the year for this calendar:-");
  173. scanf("%d", &year);
  174. i = findstartday(year);
  175. lol = printCalendar(year, i);
  176. return 0;
  177. }
Add Comment
Please, Sign In to add comment