Leap Year (If with Logical Operators)
As IF can be used for Decision making, here is an example of if and else to find out Given Year is Leap Year or not). We have used % operator and || (or operator :Any one true) , && (all the conditions must be true).
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("\n enter a year to check if leap year:");
scanf("%d",&year);
if((year%4==0)&&(year%100!=0)||(year%400==0))
{
printf("\n leap year");
}
else
{
printf("\n not leap year");
}
printf("%d",year);
getch();
}