[3/3] Checking for Leap Years using Logical Operators

Any year is entered through the keyboard, write a program to
determine whether the year is leap or not.
(Use the logical operators && and ||)


#include<stdio.h>
main()
{


int year;

printf("Enter the year to check for a leap year:");
scanf ("%d", &year);



if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))

{
printf("The entered year is a leap year.");
}
else
{

printf("The entered year is not a leap year.");
}

}


The file can be found at:
Download File


Comments

Unknown said…
simple and awesome
Ekta said…
mindblowing..............
subho said…
Awesome answer.
Can you explain how u started thinking to solve the puzzle?

Thanks,
Subhankar.
Unknown said…
I want c program for to find a leap year or not without using % and / operators.

this is hari
nhari425@gmail.com.
if u know the answer pls send to my mail...

thnk uuuuuu
Amit Kashyap said…
This comment has been removed by the author.
naresh said…
We can also use
If(year%400==0 && year%4==0)
{
Print("it is leap year:");
}
Else
{
Print("it is not leap year:");
}
}
Unknown said…
I want to do it with using only two statement in on one if
What if user enter year=100 there will be an error

Popular posts from this blog

C Program - Calculation of Area and Circumference of a Circle using Pointers

Matchstick Game using C Programming

C Program to Calculate Factorial of a number using Recursion