Source Code to Check Leap Year
/*
C program to check whether a year is leap year or not using if else
statement.*/
#include <stdio.h>
int main(){
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0) /* Checking for a century year */
{
if ( year%400 == 0)
printf("%d is a leap
year.", year);
else
printf("%d is not a leap
year.", year);
}
else
printf("%d is a leap
year.", year );
}
else
printf("%d is not a leap
year.", year);
return 0;
}
Output 1
Enter
year: 2000
2000 is a
leap year.
Output 2
Enter
year: 1900
1900 is
not a leap year.
Output 3
Enter
year: 2012
2012 is a
leap year.
No comments:
Post a Comment