-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4 no of sundays that fall on 1 st day of month.cpp
67 lines (61 loc) · 1.32 KB
/
4 no of sundays that fall on 1 st day of month.cpp
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
//min no of notes
#include<iostream>
using namespace std;
int chleap(int n)
{
if(n%4==0)
{
return 1;
}
else
return 0;
}
int main()
{
enum day {mon,tue,wed,thu,fri,sat,sun};
enum month{jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dece};
int firstday=tue;
int lastday;
int i;
int counter=0;
for(i=1901;i<=2000;i++)
{
//cout<<"hello";
for(int month=jan;month<=dece;month++)
{
switch(month)
{
case jan:
case mar:
case may:
case jul:
case aug:
case oct:
case dece:
lastday=(firstday+2)%7;
break;//break the loop within the switch not the upper loop
case apr:
case jun:
case sep:
case nov:
lastday=(firstday+1)%7;
break;
case feb:
{
if(chleap(i)==1)
lastday=(firstday)%7;
else
lastday=(firstday+6)%7;
}
break;
}
firstday=(lastday+1)%7;
if(firstday==sun)
{
counter++;
}
// month++;
}
}
cout<<counter;
}