-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProject.c
More file actions
143 lines (112 loc) · 2.19 KB
/
Project.c
File metadata and controls
143 lines (112 loc) · 2.19 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <stdio.h>
#include <stdlib.h>
//? Number of days in each month
int month_days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//!month_days[0]=0 to start indexing from 1
//? Names of all the months
char *months[] = {
"", //! to start indexing from 1
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};
int main()
{
while (1)
{
int year;
printf("Enter Year: ");
scanf("%d", &year);
int tem = day(year,2);
desgin(tem , 2,4,year);
}
return 0;
}
int day(int year , int month){
int leap = (year-1)/4;
int normal = (year-1) - leap;
int days = leap*2 + normal;
return (days+start_month(month))%7;
}
int start_month(int month , int year){
int total = 0;
int i =0 ;
for(i =1 ; i<month ; i++){
if(month == 1){
if(year %4 ==0 ){
if(year%100 == 0 ){
if(year%400 == 0 ){
total =total+month_days[i]+1;
}else{
total =total+month_days[i];
}
}else{
total =total+month_days[i];
}
}else{
total =total+month_days[i];
}
}else{
total+=month_days[i];
}
}
return total;
}
void desgin(int start_day , int month , int end , int year){
int i =0 ;
char *day[] = {"S", "M","T","W","T","F","s"};
int tem = start_day;
while(end>=month){
i =0;
tem = start_day;
for(i = 0 ; i <7 ; i++){
printf("%s " , day[i] );
}
i = 1;
int end_day = month_days[month];
// checking leap year
if(month == 2){
if(year%4 == 0 ){
if(year%100 == 0 ){
if(year%400 == 0 ){
end_day++;
}
}else{
end_day++;
}
}
}
printf("\n");
while(i<=end_day){
int j = 0;
for(; j<7 ; j++){
if(start_day==0){
if(i<10){
printf("%d " , i);
}else{
printf("%d " , i);
}
i++;
if(i >end_day){
break;
}
}else{
start_day--;
printf(" ");
}
}
printf("\n");
}
start_day = (tem+end_day)%7;
printf("\n");
month++;;
}
}