diff options
author | smlckz <smlckz@college> | 2021-12-22 14:56:13 +0530 |
---|---|---|
committer | smlckz <smlckz@college> | 2021-12-22 14:56:13 +0530 |
commit | b73983c3717642ca10e7cfe93d97609adc377da9 (patch) | |
tree | a6e9fe4c27e3caa215f8aefa9265fb52f6de4375 /assignments/02-leapyear.c | |
download | college-b73983c3717642ca10e7cfe93d97609adc377da9.tar.gz |
backup
Diffstat (limited to 'assignments/02-leapyear.c')
-rw-r--r-- | assignments/02-leapyear.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/assignments/02-leapyear.c b/assignments/02-leapyear.c new file mode 100644 index 0000000..f281dc2 --- /dev/null +++ b/assignments/02-leapyear.c @@ -0,0 +1,47 @@ +/* Leap year */ +#include <stdio.h> + +int main(void) +{ + int year; + printf("Enter a year: "); + scanf("%d", &year); + if (year <= 1200 || year >= 9999) { + printf("Invalid year.\n"); + return 0; + } + if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) + printf("%d is a leap year.\n", year); + else + printf("%d is not a leap year.\n", year); + return 0; +} + +/* +Output: +Set 1: +Enter a year: 1300 +1300 is not a leap year. + +Set 2: +Enter a year: 1600 +1600 is a leap year. + +Set 3: +Enter a year: 2008 +2008 is a leap year. + +Set 4: +Enter a year: 2003 +2003 is not a leap year. + +Set 5: +Enter a year: 1100 +Invalid year. + +Set 6: +Enter a year: 10000 +Invalid year. + +*/ + |