-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19.cpp
76 lines (73 loc) · 1.07 KB
/
19.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
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace std;
bool isLeap (int year)
{
if(year%4 ==0)
{
if (year%400==0)
{
return true;
}
else if (year%100 != 0)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
int main()
{
int weekDay = 2;
int sundaysOnFirstMonth = 0;
for (int year = 1901; year<=2000; year++)
{
for (int month = 1; month<=12; month++)
{
int days = 0;
if (month ==2)
{
if (isLeap(year)==true)
{
days = 29;
}
else
{
days = 28;
}
}
if (month != 2)
{
if ((month == 4)||(month == 6)||(month==9)||(month==11))
{
days = 30;
}
else
{
days = 31;
}
}
for (int i = 1; i<=days; i++)
{
if ((weekDay%7 == 0)&&(i==1))
{
sundaysOnFirstMonth++;
}
cout<<"Year: "<<year<<" Month: "<<month<<" Day: "<<i<<" Day of the week: "<<weekDay<<endl;
weekDay++;
if (weekDay>7)
{
weekDay -= 7;
}
}
}
}
cout<<endl<<"Sundays on the first month in the 20th century = "<<sundaysOnFirstMonth<<endl<<endl;
return 0;
}