// Description: Program that determines if the input year is a leap year // Activity Section: 1.Design with Functions // Date: 10/3/15 // by Sabrina Rispin // Test Cases: year - expected result - pass/fail // 1 - assert error - pass // 1583 - not l.y. - pass // 1584 - l.y. - pass // 1700 - not l.y. - pass // 1600 - l.y. - pass // 2000 - l.y. - pass // 2100 - not l.y. - pass //---------------------------72-characters------------------------------ #include <stdio.h> #include <stdlib.h> #include <assert.h> #define START_OF_GREG_CAL 1582 int isLeapYear (int year); int main (int argc, char * argv[]) { int year; printf("please enter the year you are interested in\n"); scanf("%d", &year); if (isLeapYear(year)) { printf("%d is a leap year!\n", year); } else { printf("%d is not a leap year!\n", year); } return EXIT_SUCCESS; } int isLeapYear (int y) { assert(y >= START_OF_GREG_CAL); int isleap = 0; if (y % 400 == 0) { isleap = 1; } else if (y % 100 == 0) { isleap = 0; } else if (y % 4 == 0) { isleap = 1; } return isleap; }
Download file: leapYearFunction.c
(1.1 KB)