/* * File: lpyr.c * ---------------- * Reads in a year and determines whether it is a * leap year. A year is a leap year if it is * divisible by four, unless it is divisible by 100. * Years divisible by 100 are leap years only if * divisible by 400. * * Modified from "leapyear.c" by Jeff Tian to demonstrate * use of nested "if" instead of compound conditions, * and the use of pre-set default value. */ #include #include "genlib.h" #include "simpio.h" main() { int year; bool isLeapYear; printf("Program to determine whether a year is a leap year.\n"); printf("What year? "); year = GetInteger(); isLeapYear = FALSE; if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) { isLeapYear = TRUE; } } else { isLeapYear = TRUE; } } if (isLeapYear) { printf("%d is a leap year.\n", year); } else { printf("%d is not a leap year.\n", year); } }