|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/cs256su21code/jun09/leapYear.c
/*
takes the leap year program we did and made it into a function
*/
#include <stdio.h>
int isLeap(int year);
int main()
{
int year;
printf("Enter a year: ");//Prompt the user for a year
scanf("%d", &year); //store the user input in the year variable
if(isLeap(year) == 1)
printf("%d is a Leap Year\n", year);
else
printf("%d is not a Leap Year\n", year);
return 0;
}
//this function returns 1 if the given year is a leap year, 0 if not.
int isLeap(int year){
if(year % 100 == 0){
if(year % 400 == 0)
return 1;
else
return 0;
} else {
if(year % 4 == 0)
return 1;
else
return 0;
}
}
|