Check Leap Year in C Programming

0
45
Check Leap Year in C Programming

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:

[indeed-social-locker sm_list=’fb,tw,,pt,go1′ sm_template=’ism_template_1′ sm_list_align=’horizontal’ sm_display_counts=’false’ sm_display_full_name=’true’ unlock_type=1 locker_template=3 sm_d_text='<h2>This content is locked</h2><p>Share This Page To Unlock The Content!</p>’ ism_overlock=’default’ ] Download Program [/indeed-social-locker]

Program 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:

[indeed-social-locker sm_list=’fb,tw,,pt,go1′ sm_template=’ism_template_1′ sm_list_align=’horizontal’ sm_display_counts=’false’ sm_display_full_name=’true’ unlock_type=1 locker_template=3 sm_d_text='<h2>This content is locked</h2><p>Share This Page To Unlock The Content!</p>’ ism_overlock=’default’ ] Download Program [/indeed-social-locker]

Read Also:

Introduction to C Programming

Multiplying two numbers in C

How to Calculate Simple Interest in C Programming

Calculate gross salary in C

Print ASCII Values Using While Loop in C Program