-
Notifications
You must be signed in to change notification settings - Fork 2
/
7_leap_year.cpp
49 lines (43 loc) · 933 Bytes
/
7_leap_year.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
// check if a given year is leap year or not
/*
Leap year is a year where we have 29 days instead of 28 in the month of february
Read more here : https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year
*/
#include<iostream>
int main(void)
{
int year;
std::cin >> year;
// detailed implemantation for beginners
/*
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
std::cout << "leap";
}
else
{
std::cout << "not leap";
}
}
else{
std::cout << "leap";
}
}
else
{
std::cout << "not leap";
}
*/
// advanced implementation
if((year%4==0) && (year%100!=0) || (year%400==0)){
std::cout<<"leap"<<std::endl;
}
else
{
std::cout<<"not leap"<<std::endl;
}
}