We can determine the leap year by applying the condition whether the given year is divisible by 4 and not divisible by 100 or given year is divisible by 400. If the condition satisfies then the given is leap year.
Output:
Enter year : 2012
2012 is Leap Year.
leap_year.c
#include <stdio.h>
#include <conio.h>
void main()
{
int year;
printf("Enter Year : ");
scanf("%d", &year);
//check for leap year.
if((year % 4 == 0 && year %100 != 0) || (year % 400 == 0))
printf("\n %d is Leap Year", year);
else
printf("\n%d is not Leap Year",year);
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int year;
printf("Enter Year : ");
scanf("%d", &year);
//check for leap year.
if((year % 4 == 0 && year %100 != 0) || (year % 400 == 0))
printf("\n %d is Leap Year", year);
else
printf("\n%d is not Leap Year",year);
getch();
}
Output:
Enter year : 2012
2012 is Leap Year.
No comments:
Post a Comment