Let’s take a look at how to check leap year in C Programming. I am referring to an awesome book called “Let us C” by “Yashwant Kanetkar” and I will post solutions to the questions asked in exercises. This is the third program of the second chapter: The Decision Control Structure. Please come back for more programs. If you are unsure about any part and more information, put it down in the comments section below or look it up on Google if you want a quick response. We try to answer all the queries as soon as possible.
Question:
Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not. (Hint: Use the % (modulus) operator)
Solution to Check Leap Year in C Programming:
Again, this is a very simple program. All you have to do is ask the user to input a year to check if it is a leap year or not. Then using the if-else conditional statements, check if the year is a leap or not. A leap year is always divisible by 4. So if the year entered by the user is divisible by 4, then the entered year is a leap year and vice-a-versa. Dumb Fact: A leap year has 29 days in February.
Download the source code:
Download ProgramProgram to Check Leap Year in C Programming:
//C Program to Check Leap year - ReadMeNow #include<stdio.h> #include<conio.h> main() { int year; clrscr(); printf("\n Enter the Year you want to find the leap year for - "); scanf("\n %d",&year); if(year%4!=0) { printf("\n %d The year you entered is not a leap year.",year); } else { printf("\n %d year is a leap year",year); } return(0); }
Output
Enter the Year you want to find the leap year for – 2011
2011 The year you entered is not a leap year.
Download the source code:
Please don’t forget to subscribe to us before you hit the download button! It helps us grow and provide more content.
Download Program