-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kalender_Abadi.c
63 lines (54 loc) · 1.53 KB
/
Kalender_Abadi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
int isLeapYear(int year);
int leapYears(int year);
int todayOf(int y, int m, int d);
long days(int y, int m, int d);
void calendar(int y, int m);
int main(void)
{
int year, month;
printf("Enter the month and year: ");
scanf("%d %d", &month, &year);
calendar(year, month);
return 0;
}
int isLeapYear(int y)
{
return (y % 400 == 0) || ((y % 4 == 0) && (y % 100 != 0));
}
int leapYears(int y)
{
return y / 4 - y / 100 + y / 400;
}
int todayOf(int y, int m, int d)
{
static int DayOfMonth[] = {-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
return DayOfMonth[m] + d + ((m > 2 && isLeapYear(y)) ? 1 : 0);
}
long days(int y, int m, int d)
{
int lastYear;
lastYear = y - 1;
return 365L * lastYear + leapYears(lastYear) + todayOf(y, m, d);
}
void calendar(int y, int m)
{
const char *NameOfMonth[] = {NULL, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
char Week[] = "Su Mo Tu We Th Fr Sa";
int DayOfMonth[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int weekOfTopDay;
int i, day;
weekOfTopDay = days(y, m, 1) % 7;
if (isLeapYear(y))
DayOfMonth[2] = 29;
printf("\n %s %d\n%s\n", NameOfMonth[m], y, Week);
for (i = 0; i < weekOfTopDay; i++)
printf(" ");
for (i = weekOfTopDay, day = 1; day <= DayOfMonth[m]; i++, day++)
{
printf("%2d ", day);
if (i % 7 == 6)
printf("\n");
}
printf("\n");
}