A leap year in the Gregorian calendar is a year in which February has 29 days in
ID: 3694150 • Letter: A
Question
A leap year in the Gregorian calendar is a year in which February has 29 days instead of the usual 28 days. These special extra days were added in 1582 to keep the calendar year synchronized with the astronomical or seasonal year. According to Wikipedia: Every year that is exactly divisible by 4 is a leap year, except for years that arc exactly divisible by 100, but years divisible by 100 are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the year 2000 is. Note that before the Leap Year system was developed in 1582, Leap Years did not exist, so any year before 1582 can never be a leap year! For example: 2000 was a leap year. 2400 will be a leap year. 2004, 2008 and 2016 arc all leap years as well. Write a function that accepts an integer year value and returns 1 if it is a Leap Year and 0 if it is not following this function prototype: int isLeapYear(int);Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
//funtion prototype
int isLeapYear(int);
int main()
{
int year;
printf("Enter a year: ");
//read year
scanf("%d",&year);
//calling and checking the year is leap or not
if(isLeapYear(year))
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
return 0;
}
//function to check given year is leap year or not
int isLeapYear(int year)
{
if(year%4 == 0)
{
if( year%100 == 0) /* Checking for a century year */
{
if ( year%400 == 0)
return 1;
else
return 0;
}
else
return 1;
}
else
return 0;
}
OUTPUT:
Enter a year: 1900
1900 is not a leap year.
Process returned 0 (0x0) execution time : 3.524 s
Press any key to continue.
Enter a year: 2004
2004 is a leap year.
Process returned 0 (0x0) execution time : 4.608 s
Press any key to continue.
NOTE: if you want in any other prog language, please comment
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.