-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18_Logical_Operators.c
29 lines (22 loc) · 974 Bytes
/
18_Logical_Operators.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
int main() {
int year;
int startYear = 1900;
int endYear = 2100;
printf("Enter a year: ");
scanf("%d", &year);
// Check if the year is a leap year
int isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
// Check if the year is within the specified range
int isWithinRange = (year >= startYear && year <= endYear);
if (isLeapYear && isWithinRange) {
printf("%d is a leap year and is within the range %d to %d.\n", year, startYear, endYear);
} else if (!isLeapYear && isWithinRange) {
printf("%d is not a leap year but is within the range %d to %d.\n", year, startYear, endYear);
} else if (isLeapYear && !isWithinRange) {
printf("%d is a leap year but is not within the range %d to %d.\n", year, startYear, endYear);
} else {
printf("%d is not a leap year and is not within the range %d to %d.\n", year, startYear, endYear);
}
return 0;
}