Active Logic: Decision Control Structures
Master simple if, two-way if-else, multi-way if-else-if ladders, relational operators, and logical operators (&&, ||, !).
C Branching Constructs & Operators
| Construct / Operator | Syntax | Key Rule & Trap |
|---|---|---|
| Equality Operator | a == b | Assignment a = b is a bug! Use == |
| Logical AND | cond1 && cond2 | Both conditions MUST be true |
| Logical OR | cond1 || cond2 | At least ONE condition MUST be true |
| If-Else Ladder | if ... else if ... else | First true branch executes; rest skipped |
| Nested If | if (c1) { if (c2) ... } | Evaluates inner condition only if outer is true |
🎯 Learning Philosophy: Active Logic Building
Test your decision-making logic across 3 Interactive Learning Modes:
- 🧠Tab 1 (Logic & Hints): Decision rules & truth table breakdowns.
- 🧩 Tab 2 (Logic Puzzle): Fill in missing boolean operators (
==,&&,||) & run live testers. - 💻 Tab 3 (C Solution): Reference verified C code solutions.
Odd / Even Check & Multiples Verification
Determine if a number is even (num % 2 == 0) or odd, and verify if integer A is a multiple of integer B (a % b == 0).
Modulus Branching Logic
- Even Condition:
n % 2 == 0(Remainder when divided by 2 is 0) - Odd Condition:
n % 2 != 0(Remainder is 1 or -1) - Multiple Condition:
a % b == 0(No remainder when A is divided by B)
Interactive Logic Hints
if (n % 2 = 0) causes a compilation syntax error! = is assignment, == is comparison!a % b!🧩 Complete the Even/Odd & Multiples Logic
if (num % 2 0) {
printf("EVEN");
}
if (a b 0) {
printf("A is multiple of B");
}
🔢 Live Even/Odd & Divisibility Tester
Leap Year Detection (The Century Rule)
A year is a leap year if it is divisible by 400 OR (divisible by 4 AND NOT divisible by 100).
Leap Year Decision Logic
- Rule 1 (Century Years): Year % 400 == 0 (e.g. 2000 is leap)
- Rule 2 (Regular Years): Year % 4 == 0 AND Year % 100 != 0 (e.g. 2024 is leap, 1900 is NOT)
- Combined:
(year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)
Interactive Logic Hints
🧩 Complete the Leap Year Compound Boolean Logic
printf("Leap Year");
}
📅 Leap Year Rule Evaluator
Roots of a Quadratic Equation (ax2 + bx + c = 0)
Classifies discriminant D = b2 - 4ac using multi-way if-else-if ladder (D > 0, D == 0, D < 0).
Discriminant Conditions
- disc > 0: Real & Distinct roots:
(-b ± √D) / (2a) - disc == 0: Real & Equal roots:
-b / (2a) - disc < 0: Complex Imaginary roots:
-b/(2a) ± i √(-D)/(2a)
Interactive Logic Hints
🧩 Complete Discriminant Ladder Conditions
if (disc 0) {
printf("Real & Distinct");
} else if (disc 0) {
printf("Real & Equal");
} else {
printf("Imaginary");
}
🧮 Interactive Quadratic Solver
Grades Ladder & Triangle Inequality Validation
Assigns letter grades using if-else-if ladder and validates triangle inequality (a + b > c && a + c > b && b + c > a).
Triangle Inequality Theorem
- The sum of any two sides MUST be strictly greater than the third side!
- Condition:
(a + b > c) && (a + c > b) && (b + c > a) - If valid, semi-perimeter
s = (a+b+c)/2.0& Heron's Areasqrt(s*(s-a)*(s-b)*(s-c))
Interactive Logic Hints
&& enforces all 3!🧩 Complete Triangle Inequality & Grade Logic
else if (marks >= 80) printf("A");
if (a + b c a + c > b && b + c > a) {
s = (a + b + c) / 2.0;
area = sqrt(s * (s-a) * (s-b) * (s-c));
}
📊 Grade & Triangle Tester
Days in a Month Calculator (Leap Year Aware)
Groups months with 31 days, 30 days, and handles February (28 vs 29 days based on leap year).
Month Days Rules
- 31 Days: Month 1, 3, 5, 7, 8, 10, 12 (Use OR
||) - 30 Days: Month 4, 6, 9, 11
- February (Month 2): 29 days if leap year, 28 days otherwise!
Interactive Logic Hints
&& would be impossible!🧩 Complete Month Grouping Conditions
printf("31 Days");
} else if (m == 4 || m == 6 || m == 9 || m == 11) {
printf("30 Days");
} else if (m 2) {
// February leap check...
}
📆 Month Days Calculator
Character Classifier (Vowel, Consonant, Digit, Special)
Classifies input character using vowel checks and <ctype.h> helper functions (isalpha, isdigit).
Classification Rules
- Header required:
#include <ctype.h> - Vowels:
ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'(also uppercase A,E,I,O,U) - Alphabet Check:
isalpha(ch) - Digit Check:
isdigit(ch)
Interactive Logic Hints
" %c" instructs scanf to skip any leftover newline or whitespace characters!🧩 Complete Character Classifier Logic
if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') printf("Vowel");
else if ((ch)) printf("Consonant");
else if ((ch)) printf("Digit");