Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void) {
- int y, m;
- setbuf(stdout, NULL);
- for (;;) {
- fputs("year? ", stdout);
- if (scanf("%d", &y) != 1) { exit(1); }
- if (1581 < y) { break; }
- }
- for (;;) {
- fputs("month? ", stdout);
- if (scanf("%d", &m) != 1) { exit(1); }
- if (0 < m && m < 13) { break; }
- }
- int w = 0;
- {
- int yy = y, mm = m;
- if (mm < 3) { --yy, mm += 12; }
- w = (yy + yy / 4 - yy / 100 + yy / 400 + (13 * mm + 8) / 5 + 1) % 7;
- }
- int days =
- (m == 4 || m == 6 || m == 9 || m == 11)
- ? 30
- : (m == 2) ? (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0) ? 29 : 28)
- : 31;
- puts(""), puts(" Sun Mon Tue Wed Thu Fri Sat");
- for (int d = 1, c = 0; d <= days;) {
- if (0 < w--) {
- fputs(" ", stdout), ++c;
- continue;
- }
- printf("%4d", d++);
- if (++c % 7 == 0) { puts(""); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement