🧠 Decision Making in C Programming

A Complete Beginner Guide with Examples and Output

πŸ“˜ Part of the C Programming Beginner Series by Learning Growth Hub


✨ Introduction

In real life, we make decisions every day.

If it is raining → we take an umbrella.
If marks are above 40 → we pass the exam.
If option 1 is selected → we perform addition.

Similarly, in C programming, we use decision-making statements to control the flow of execution.

Decision making allows a program to execute specific blocks of code only when a given condition is true.

In this beginner-friendly guide, you will learn:

  • What is decision making in C

  • if statement

  • if-else statement

  • else-if ladder

  • Nested if

  • switch statement

  • Programs with line-by-line comments

  • Outputs for each program

  • Practice questions

Let’s start πŸš€


1️⃣ What is Decision Making in C?

πŸ“Œ Description

Decision making allows a program to:

✔ Check a condition
✔ Decide whether it is true or false
✔ Execute specific code based on that result

It helps programs behave intelligently based on input or logic.

Conditions usually use:

  • Relational operators (>, <, ==, !=)

  • Logical operators (&&, ||, !)

If condition is TRUE → block executes
If condition is FALSE → block is skipped


2️⃣ The if Statement

πŸ“Œ Description

The if statement is the simplest decision-making statement in C.

It executes a block of code only when the given condition is true.
If the condition is false, the block is skipped.

It is commonly used to validate input or check simple conditions.


πŸ“Œ Syntax

if (condition) { // code to execute }

πŸ§ͺ Example 1: Check if Number is Positive

#include <stdio.h> // Header file for input and output functions int main() { // Main function starts int num = 5; // Declare and initialize variable num with value 5 if (num > 0) { // Check if num is greater than 0 printf("Number is Positive"); // Print message if condition is true } return 0; // End of program }

πŸ“€ Output:

Number is Positive

3️⃣ The if-else Statement

πŸ“Œ Description

The if-else statement is used when we want two possible outcomes.

If the condition is true → one block executes.
If the condition is false → another block executes.

It is useful when checking things like even/odd, pass/fail, eligible/not eligible, etc.


πŸ§ͺ Example 2: Check Even or Odd

#include <stdio.h> // Standard input-output header int main() { // Main function int num = 4; // Declare variable num and assign value 4 if (num % 2 == 0) { // Check if remainder when divided by 2 is 0 printf("Even Number"); // Executes if condition is true } else { // Executes if condition is false printf("Odd Number"); // Print Odd Number } return 0; // Program ends }

πŸ“€ Output:

Even Number

4️⃣ The else-if Ladder

πŸ“Œ Description

The else-if ladder is used when we need to check multiple conditions.

C checks conditions from top to bottom.
As soon as one condition becomes true, its block executes and the remaining conditions are skipped.

It is commonly used in grading systems and menu-based programs.


πŸ§ͺ Example 3: Grade Calculator

#include <stdio.h> // Include standard input-output library int main() { // Main function starts int marks = 75; // Declare marks variable and assign 75 if (marks >= 90) { // Check if marks >= 90 printf("Grade A"); // Execute if true } else if (marks >= 70) { // Check if marks >= 70 printf("Grade B"); // Execute if true } else if (marks >= 50) { // Check if marks >= 50 printf("Grade C"); // Execute if true } else { // If none of above conditions are true printf("Fail"); // Execute this block } return 0; // End program }

πŸ“€ Output:

Grade B

5️⃣ Nested if Statement

πŸ“Œ Description

A nested if means placing one if statement inside another if.

The second condition is checked only if the first condition is true.

This helps in creating more detailed decision logic.


πŸ§ͺ Example 4: Check Positive and Even

#include <stdio.h> // Standard input-output library int main() { // Main function int num = 8; // Declare variable num if (num > 0) { // Check if number is positive if (num % 2 == 0) { // Inside first if, check if even printf("Positive Even Number"); // Print result } } return 0; // End of program }

πŸ“€ Output:

Positive Even Number

6️⃣ The switch Statement

πŸ“Œ Description

The switch statement is used when we compare a single variable against multiple fixed values.

Instead of writing many if-else statements, switch makes the code cleaner and easier to read.

Each case represents a possible value.


πŸ§ͺ Example 5: Simple Calculator Menu

#include <stdio.h> // Standard input-output library int main() { // Main function int choice = 2; // Declare variable choice switch(choice) { // Switch checks value of choice case 1: // If choice == 1 printf("Addition Selected"); break; // Exit switch case 2: // If choice == 2 printf("Subtraction Selected"); break; case 3: // If choice == 3 printf("Multiplication Selected"); break; default: // If none match printf("Invalid Choice"); } return 0; // End program }

πŸ“€ Output:

Subtraction Selected

πŸ”Ž Difference Between if-else and switch

if-else switch
Used for complex conditions Used for fixed values
Supports logical operators (&&, ||, !) Does not support complex logical conditions
More flexible Cleaner for menu-based programs
Can compare ranges (e.g., marks >= 50) Works only with specific constant values


πŸ§ͺ Practice Questions (Try Yourself)

  • Write a program to find the largest of 3 numbers.

  • Write a program to check whether a year is a leap year.

  • Create a menu-driven calculator using switch.

  • Write a program to check whether a character is a vowel or consonant.

  • Write a program to check voting eligibility (age ≥ 18).

πŸ’‘ Try solving before checking answers online. Practice builds confidence.


🎯 Why Decision Making is Important

Without decision-making statements:

  • Programs cannot react

  • Programs cannot validate input

  • Programs cannot create real-world logic

Every real-world software uses decision making.


πŸ“Œ Quick Revision Summary

Before we conclude, here is a quick summary table to help you revise all decision-making statements at a glance.



This summary table helps you quickly revise when to use each decision-making statement in C programming. You can screenshot this table for quick exam revision.

✅ Conclusion

In this blog, you learned:

✔ What decision making is in C
✔ if statement
✔ if-else statement
✔ else-if ladder
✔ Nested if
✔ switch statement
✔ Programs with output
✔ Practice problems

If you practice these programs today, you will feel confident tomorrow.


🌱 Reflection

Decision making is what gives intelligence to a program.

When you use if, else, or switch, you are not just writing code —
you are teaching your program how to think and respond.

Mastering conditions is the first real step toward becoming a confident programmer.


πŸ“Œ What’s Next?

πŸ‘‰ In the next blog, we will learn Loops in C (for, while, do-while) — which allow us to repeat tasks efficiently.

Stay tuned to Learning Growth Hub 🌱


✨ Written by Krishna Popat

🌱 Founder, Learning Growth Hub 

Comments

Popular posts from this blog

🌟 The Honest Journey of a Student: Learning, Failing, and Growing

“C Programming for Beginners: Master Variables, Data Types, and Memory (Bits Explained)”