Advertisement
_who___

Untitled

May 17th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <locale.h>
  7.  
  8. void print_calendar(int year, int month)
  9. {
  10. int days_in_month[] = { 31, 28 + (year % 4 == 0 && year % 100 != 0 || year % 400 == 0), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  11. char* month_names[] = { "", "������", "�������", "����", "������", "���", "����", "����", "������", "��������", "�������", "������", "�������" };
  12.  
  13. printf("%s %04d\n", month_names[month], year);
  14. printf("�� �� �� �� �� �� ��\n");
  15.  
  16. int dow = get_day_of_week(year, month, 1);
  17.  
  18. for (int i = 0; i < dow; i++)
  19. {
  20. printf(" ");
  21. }
  22.  
  23. for (int day = 1; day <= days_in_month[month - 1]; day++)
  24. {
  25. printf("%2d ", day);
  26.  
  27. if ((day + dow) % 7 == 0 || day == days_in_month[month - 1])
  28. {
  29. printf("\n");
  30. }
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. system("chcp 1251");
  37. setlocale(LC_ALL, "rus");
  38.  
  39. char input[11];
  40. time_t t = time(NULL);
  41.  
  42. struct tm now = *localtime(&t);
  43. int year = now.tm_year + 1900;
  44. int month = now.tm_mon + 1;
  45. int day = now.tm_mday;
  46. char now1[] = "now";
  47.  
  48. printf("������� ���� � ������� ����.��.��, ����.��, ���� ��� now: ");
  49. scanf("%s", input);
  50.  
  51. if (strcmp(input, now1) == 0)
  52. {
  53. printf("����������� ����: %04d.%02d.%02d\n", year, month, day);
  54. }
  55. else if (strlen(input) == 10 && input[4] == '.' && input[7] == '.')
  56. {
  57. struct tm new;
  58. new.tm_year = atoi(input);
  59. new.tm_mon = atoi(input + 5);
  60. new.tm_wday = atoi(input + 8);
  61.  
  62. time_t�t;
  63. struct�tm�* p;
  64. char�s[80];
  65. char* format� = "%A�%B�%Y";
  66. t� = time(NULL);
  67. p� = gmtime(&t);
  68. strftime(s, 80, format, p);�
  69. printf("Time:�%s\n", s);
  70. return�0;
  71. }
  72.  
  73. time_t t = mktime(timeinfo);
  74. char buffer[80];
  75. strftime(buffer, 80, "%A", localtime(&t));
  76.  
  77. printf("���� ������: %s\n", buffer);
  78.  
  79. int dow = get_day_of_week(year, month, day);
  80.  
  81. switch (dow)
  82. {
  83. case 0:
  84. printf("���� ������ ��� ���� %s: �����������\n", input);
  85. break;
  86. case 1:
  87. printf("���� ������ ��� ���� %s: �����������\n", input);
  88. break;
  89. case 2:
  90. printf("���� ������ ��� ���� %s: �������\n", input);
  91. break;
  92. case 3:
  93. printf("���� ������ ��� ���� %s: �����\n", input);
  94. break;
  95. case 4:
  96. printf("���� ������ ��� ���� %s: �������\n", input);
  97. break;
  98. case 5:
  99. printf("���� ������ ��� ���� %s: �������\n", input);
  100. break;
  101. case 6:
  102. printf("���� ������ ��� ���� %s: �������\n", input);
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108. else if (strlen(input) == 7 && input[4] == '.')
  109. {
  110. year = atoi(input);
  111. month = atoi(input + 5);
  112.  
  113. printf("��������� �� %04d.%02d:\n", year, month);
  114. print_calendar(year, month);
  115. }
  116. else if (strlen(input) == 4)
  117. {
  118. year = atoi(input);
  119.  
  120. printf("��������� �� %04d:\n", year);
  121.  
  122. for (int i = 1; i <= 12; i++)
  123. {
  124. print_calendar(year, i);
  125. }
  126. }
  127. else
  128. {
  129. printf("������: ������������ ������ ����\n");
  130. return 1;
  131. }
  132. return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement