🚦 Control Flow & Conditionals
Decision-making is the heart of programming. Use these problems to practice if, else if, else,
and switch statements along with logical operators (&&, ||, !).
Examples
1. Even or Odd
Rating: Newbie | Difficulty: Easy Input an integer and check if it is even or odd.
💡 Hint
Use the modulus
operator: if (num % 2 == 0).
2. Maximum of Two Numbers
Rating: Newbie | Difficulty: Easy Input two numbers and print the larger one.
💡 Hint
Use a simple `if (a
b)`.
3. Maximum of Three Numbers
Rating: Beginner | Difficulty: Easy Input three numbers and find the maximum among them.
💡 Hint
Use nested
if or logical &&: if (a > b && a > c).
4. Leap Year Checker
Rating: Intermediate | Difficulty: Medium Input a year and check if it is a leap year or not.
💡 Hint
A year is a
leap year if: (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0).
5. Positive, Negative, or Zero
Rating: Newbie | Difficulty: Easy Input a number and determine if it is positive, negative, or zero.
💡 Hint
Use if, else if, and else.
6. Divisibility Check
Rating: Beginner | Difficulty: Easy Check if a number is divisible by both 5 and 11.
💡 Hint
if (num % 5 == 0 && num % 11 == 0).
7. Vowel or Consonant
Rating: Beginner | Difficulty: Easy Input a character and check if it is a vowel (a, e, i, o, u) or a consonant.
💡 Hint
Remember to check for both uppercase and lowercase.
8. Grade Calculator
Rating: Beginner | Difficulty: Easy Input marks of 5 subjects. Calculate percentage and assign grades:
-
90%: Grade A
-
80%: Grade B
-
70%: Grade C
- < 40%: Fail
💡 Hint
Use an if-else if ladder.
9. Week Day Name (Switch Case)
Rating: Beginner | Difficulty: Easy
Input a number (1-7) and print the corresponding week day (Monday, Tuesday, etc.) using a switch
statement.
💡 Hint
switch(day) { case 1: print("Monday"); break; ... }
10. Month Days
Rating: Intermediate | Difficulty: Medium Input a month number (1-12) and print the total number of days in that month.
💡 Hint
Groups cases like 1, 3, 5, 7, 8, 10, 12 for 31 days. Don't forget February (28/29 days)!
11. Quadratic Equation Roots
Rating: Advanced | Difficulty: Hard
Find the roots of a quadratic equation ax² + bx + c = 0.
💡 Hint
Calculate discriminant D = b² - 4ac. If D > 0 (real roots), D == 0 (equal roots), D < 0
(imaginary roots).
12. Profit or Loss
Rating: Beginner | Difficulty: Easy Input Cost Price and Selling Price. Calculate profit or loss amount.
💡 Hint
if (SP > CP) then Profit, else Loss.
13. Electricity Bill Calculator
Rating: Advanced | Difficulty: Hard Calculate total electricity bill based on units consumed:
- First 50 units: ₹0.50/unit
- Next 100 units: ₹0.75/unit
- Next 100 units: ₹1.20/unit
- Above 250 units: ₹1.50/unit
- An additional surcharge of 20% is added to the bill.
💡 Hint
Calculate step-by-step. If units = 120, bill = (50 * 0.50) + (70 * 0.75). Then add 20% surcharge.
14. Triangle Validity (Angles)
Rating: Beginner | Difficulty: Easy Input three angles of a triangle and check if the triangle is valid.
💡 Hint
The sum of angles must be exactly 180.
15. Triangle Type (Sides)
Rating: Intermediate | Difficulty: Medium Input three sides of a triangle and check if it is Equilateral, Isosceles, or Scalene.
💡 Hint
Equilateral: all sides equal. Isosceles: any two equal. Scalene: none equal.
← Previous: Basic Arithmetic | Next Topic: Loops →