A leap year has 366 days, while an ordinary year has 365 days. The task is to check whether a given year is a leap year through a program.
The logic of judgment can be implemented by checking whether the year is divisible by 400 or 4, but if it is not divisible by these two numbers, it is an ordinary year.
Input-: year=2000 Output-: 2000 is a Leap Year Input-: year=101 Output-: 101 is not a Leap year
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
#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; }
2000 is a Leap Year 101 is not a Leap Year
The above is the detailed content of Write a program in C language to check if a given year is a leap year or not. For more information, please follow other related articles on the PHP Chinese website!