Skip to content

Commit e94a9c9

Browse files
committed
🚀 Exercism leap check implementation
1 parent 0649be1 commit e94a9c9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ add_executable(AscciArt src/strings/ascii_art.cpp)
1212
add_executable(Factorial src/factorial.cpp)
1313
add_executable(ReverseString src/strings/reverse.cpp)
1414

15+
add_executable(Leap src/exercism/leap.cpp)
1516
add_executable(Trinaries src/exercism/trinaries.cpp)

src/exercism/leap.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
3+
/**
4+
* A given year is leap when:
5+
* - Evenly divisible by 4
6+
* - No evenly divisible by 100
7+
* - No evenly divisible by 400
8+
*
9+
* @param year Year to test
10+
* @return Indicates if given year is leap
11+
*/
12+
bool is_leap_year(int year) {
13+
return year % 4 == 0 && year % 100 != 0 && year % 400 != 0;
14+
}
15+
16+
int main() {
17+
int year;
18+
19+
std::cout << "This program checks if a given year is leap" << std::endl;
20+
std::cout << "Enter year to check: ";
21+
std::cin >> year;
22+
23+
if (is_leap_year(year)) {
24+
std::cout << year << " is leap.";
25+
} else {
26+
std::cout << year << " is not leap.";
27+
}
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)