"카타 7급 Leap Years"의 두 판 사이의 차이

(새 문서: ==C== {{카타|7급|C|1}} <source lang='c'> </source>)
 
잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 8개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==C==
==C==
{{카타|7급|C|1}}
{{카타|7급|C|1}}
<source lang='c'>
<syntaxhighlight lang='c'>
</source>
#include <stdbool.h>
bool IsLeapYear(int year) {
  if( year%400 == 0 ) return true;
  if( year%100 == 0 ) return false;
  return !(year%4);
}
</syntaxhighlight>
<syntaxhighlight lang='c'>
#include <stdbool.h>
bool IsLeapYear(int year) {
  if( year%400 == 0 ) return true;
  if( year%100 == 0 ) return false;
  if( year%4 == 0) return true;
  return false;
}
</syntaxhighlight>
<syntaxhighlight lang='c'>
#include <stdbool.h>
bool IsLeapYear(int year) {
  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
</syntaxhighlight>
 
==C++==
{{카타|7급|C++|1}}
<syntaxhighlight lang='cpp'>
#include <stdbool.h>
bool IsLeapYear(int year) {
  if( year%400 == 0 ) return true;
  if( year%100 == 0 ) return false;
  return !(year%4);
}
</syntaxhighlight>
<syntaxhighlight lang='cpp'>
#include <stdbool.h>
bool IsLeapYear(int year) {
  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
</syntaxhighlight>
 
==Kotlin==
{{카타|7급|Kotlin|1}}
<syntaxhighlight lang='kotlin'>
fun isLeapYear(year: Int) : Boolean {
  if( year%400 == 0 ) return true
  if( year%100 == 0 ) return false
  return( year%4 == 0 )
}
</syntaxhighlight>
<syntaxhighlight lang='kotlin'>
fun isLeapYear(year: Int) = java.time.Year.of(year).isLeap
</syntaxhighlight>
<syntaxhighlight lang='kotlin'>
fun isLeapYear(year: Int) = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)
</syntaxhighlight>

2020년 11월 2일 (월) 02:41 기준 최신판

1 C[ | ]

#include <stdbool.h>
bool IsLeapYear(int year) {
  if( year%400 == 0 ) return true;
  if( year%100 == 0 ) return false;
  return !(year%4);
}
#include <stdbool.h>
bool IsLeapYear(int year) {
  if( year%400 == 0 ) return true;
  if( year%100 == 0 ) return false;
  if( year%4 == 0) return true;
  return false;
}
#include <stdbool.h>
bool IsLeapYear(int year) {
  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

2 C++[ | ]

#include <stdbool.h>
bool IsLeapYear(int year) {
  if( year%400 == 0 ) return true;
  if( year%100 == 0 ) return false;
  return !(year%4);
}
#include <stdbool.h>
bool IsLeapYear(int year) {
  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

3 Kotlin[ | ]

fun isLeapYear(year: Int) : Boolean {
  if( year%400 == 0 ) return true
  if( year%100 == 0 ) return false
  return( year%4 == 0 )
}
fun isLeapYear(year: Int) = java.time.Year.of(year).isLeap
fun isLeapYear(year: Int) = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}