>  기사  >  백엔드 개발  >  해당 연도가 윤년인지 확인하는 프로그램을 C 언어로 작성하세요.

해당 연도가 윤년인지 확인하는 프로그램을 C 언어로 작성하세요.

王林
王林앞으로
2023-09-20 15:33:101415검색

해당 연도가 윤년인지 확인하는 프로그램을 C 언어로 작성하세요.

윤년은 366일, 평년은 365일을 갖는 해가 윤년인지를 프로그램을 통해 확인하는 작업입니다.

판단의 논리는 연도가 400으로 나누어지는지, 4로 나누어지는지 확인하면 알 수 있지만, 이 두 숫자로 나누어지지 않으면 보통연도입니다.

Example

Input-: year=2000
Output-: 2000 is a Leap Year

Input-: year=101
Output-: 101 is not a Leap year

Algorithm

Start
Step 1 -> declare function bool to check if year if a leap year or not
bool check(int year)
   IF year % 400 = 0 || year%4 = 0
      return true
   End
   Else
      return false
   End
Step 2 -> In main()
   Declare variable as int year = 2000
   Set check(year)? printf("%d is a Leap Year",year): printf("%d is not a Leap Year",year)
   Set year = 10
   Set check(year)? printf("%d is a Leap Year",year): printf("</p><p>%d is not a Leap Year",year);
Stop

Example

#include <stdio.h>
#include <stdbool.h>
//bool to check if year if a leap year or not
bool check(int year){
   // If a year is multiple of 400 or multiple of 4 then it is a leap year
   if (year % 400 == 0 || year%4 == 0)
      return true;
   else
      return false;
}
int main(){
   int year = 2000;
   check(year)? printf("%d is a Leap Year",year): printf("%d is not a Leap Year",year);
   year = 101;
   check(year)? printf("%d is a Leap Year",year): printf("</p><p>%d is not a Leap Year",year);
   return 0;
}

Output

2000 is a Leap Year
101 is not a Leap Year

위 내용은 해당 연도가 윤년인지 확인하는 프로그램을 C 언어로 작성하세요.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제