summary refs log tree commit diff stats
path: root/programs/leap-year-fn.c
diff options
context:
space:
mode:
authorsmlckz <smlckz@college>2021-12-22 14:56:13 +0530
committersmlckz <smlckz@college>2021-12-22 14:56:13 +0530
commitb73983c3717642ca10e7cfe93d97609adc377da9 (patch)
treea6e9fe4c27e3caa215f8aefa9265fb52f6de4375 /programs/leap-year-fn.c
downloadcollege-b73983c3717642ca10e7cfe93d97609adc377da9.tar.gz
backup
Diffstat (limited to 'programs/leap-year-fn.c')
-rw-r--r--programs/leap-year-fn.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/programs/leap-year-fn.c b/programs/leap-year-fn.c
new file mode 100644
index 0000000..43842a9
--- /dev/null
+++ b/programs/leap-year-fn.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <stdbool.h>
+
+bool is_leap_year(int y)
+{
+	return y % 400 == 0 || (y % 100 != 0 && y % 4 == 0);
+}
+
+int main(void)
+{
+	int year;
+	printf("To check whether a given year is leap year or not\n\n");
+	printf("Enter a year: ");
+	scanf("%d", &year);
+	if (year <= 1200 || year >= 9999) {
+		printf("Invalid year.\n");
+		return 0;
+	}
+	printf("%d is%s a leap year.\n", year, is_leap_year(year) ? "" : " not");
+	return 0;
+}
+
+/*
+Output:
+Set 1:
+
+
+Set 2:
+
+Set 3:
+
+Set 4:
+
+*/
+
pre>