summary refs log tree commit diff stats
path: root/assignments/02-leapyear.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 /assignments/02-leapyear.c
downloadcollege-b73983c3717642ca10e7cfe93d97609adc377da9.tar.gz
backup
Diffstat (limited to 'assignments/02-leapyear.c')
-rw-r--r--assignments/02-leapyear.c47
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.
+
+*/
+