윤년은 366일로 구성된 1년입니다. 4년마다 윤년을 맞이하게 됩니다.
콘솔을 통해 사용자가 지정한 연도가 도약인지 아닌지 확인하기 위해 구현할 로직 -
if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))
이 조건이 충족되면 주어진 연도는 윤년입니다. 그렇지 않으면 그렇지 않습니다.
예시
다음은 If 조건을 사용하여 윤년을 확인하는 C 프로그램입니다 -
#include <stdio.h>
int main(){
int year;
printf("Enter any year you wish \n ");
scanf(" %d ", &year);
if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))
printf("\n %d is a Leap Year. \n", year);
else
printf("\n %d is not the Leap Year. \n", year);
return 0;
} 출력
위의 프로그램이 실행되면 다음과 같은 결과가 생성됩니다 -
Enter any year you wish 2045 2045 is not the Leap Year.