85 lines
2.1 KiB
Plaintext
Raw Normal View History

2025-11-23 15:07:19 +01:00
int main() {
printf("=== Logical Operators Tests ===\n");
printf("Test 1: AND operator (&&)\n");
int a = 1;
int b = 1;
if (a && b) {
printf("1 && 1 = true\n");
}
int c = 1;
int d = 0;
if (c && d) {
printf("1 && 0 = true (SHOULD NOT PRINT)\n");
} else {
printf("1 && 0 = false\n");
}
int e = 0;
int f = 0;
if (e && f) {
printf("0 && 0 = true (SHOULD NOT PRINT)\n");
} else {
printf("0 && 0 = false\n");
}
printf("PASS: AND operator works\n");
printf("Test 2: OR operator (||)\n");
if (a || b) {
printf("1 || 1 = true\n");
}
if (c || d) {
printf("1 || 0 = true\n");
}
if (e || f) {
printf("0 || 0 = true (SHOULD NOT PRINT)\n");
} else {
printf("0 || 0 = false\n");
}
printf("PASS: OR operator works\n");
printf("Test 3: Combined logical operations\n");
int x = 5;
int y = 10;
int z = 15;
if (x < y && y < z) {
printf("5 < 10 && 10 < 15 = true\n");
}
if (x > y || y < z) {
printf("5 > 10 || 10 < 15 = true\n");
}
if (x > y && y > z) {
printf("5 > 10 && 10 > 15 = true (SHOULD NOT PRINT)\n");
} else {
printf("5 > 10 && 10 > 15 = false\n");
}
printf("PASS: Combined logical operations work\n");
printf("Test 4: Logical operators in while loops\n");
int i = 0;
int j = 10;
while (i < 5 && j > 5) {
i = i + 1;
j = j - 1;
}
printf("After loop with &&: i = %d, j = %d\n", i, j);
printf("PASS: Logical operators in loops work\n");
printf("Test 5: Complex conditions\n");
int age = 25;
int hasLicense = 1;
int hasInsurance = 1;
if ((age >= 18 && hasLicense) && hasInsurance) {
printf("Can drive: age >= 18, has license and insurance\n");
}
int temp = 30;
if (temp < 0 || temp > 35) {
printf("Extreme temperature (SHOULD NOT PRINT)\n");
} else {
printf("Normal temperature range\n");
}
printf("PASS: Complex conditions work\n");
printf("\n=== All Logical Operators Tests Completed ===\n");
return 0;
}