Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions SampleCodes/charArray/strLeap.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
2월달이 29일까지 있는 윤년을 판독하는 문제. -> 4년에 한 번씩, 100년 단위는 윤년에 해당하지 않음. 그러나 400년 단위일 때는 무조건 윤년에 해당.

1. 조건문 사용

```cpp
#include <iostream>

using namespace std;

int main()
{

int year;

cin >> year;


if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
cout << year << "년은 윤년입니다." << endl;
}
else
{
cout << year << "년은 윤년이 아닙니다." << endl;
}
}
```

2. 배열&조건문 사용

```cpp
#include <iostream>

using namespace std;

int main()
{

int year;

cin >> year;

char str1[] = "년은 윤년입니다.";
char str2[] = "년은 윤년이 아닙니다.";

if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
cout << year << str1 << endl;
}
else
{
cout << year << str2 << endl;
}
}
```