Leap Year Function
This is a warmup exercise.
It is not compulsory, and may be
completed individually or with your lab partner.
For this exercise, you are going to take your leap year program that you wrote last week and put the logic of calculating whether it is a leap year into a function.
The function prototype should be int isLeapYear(int year)
. It should
return 0 if it is not a leap year and 1 if it is a leap year. Your leap
year function must not print anything. You should call this function
from your main function, which is where you print the result.
Some Examples
$ ./leapYear2 Enter a year after 1582: 12 12 is before 1582.
$ ./leapYear2 Enter a year after 1582: 2000 2000 is a leap year.
$ ./leapYear2 Enter a year after 1582: 2004 2004 is a leap year.
$ ./leapYear2 Enter a year after 1582: 2001 2001 is not a leap year.
$ ./leapYear2 Enter a year after 1582: 2100 2100 is not a leap year.
To run some simple automated tests:
$ 1511 autotest leapYear2
To run Styl-o-matic:
$ 1511 stylomatic leapYear2.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk03_leapYear2
Or, if you are working from home, upload the relevant file(s) to the wk03_leapYear2 activity on Give Online.