![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to check if a given year is leap year in C
Leap year has 366 days whereas a normal year has 365 days and the task is to check through the program whether the given year is a leap year or not.
The logic for it can be through checking if year is divided by 400 or 4 but if the number is not divided by either of the number than it will be a normal year.
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("
%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("
%d is not a Leap Year",year); return 0; }
Output
2000 is a Leap Year 101 is not a Leap Year
Advertisements