KEMBAR78
C Language Notes-1 | PDF | Pointer (Computer Programming) | Computer Programming
0% found this document useful (0 votes)
6 views20 pages

C Language Notes-1

Uploaded by

popshur5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

C Language Notes-1

Uploaded by

popshur5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

C

Mastering
Problem
Solving
Through
© Copyright Page
Title: Mastering Problem Solving Through C - Using Notes!
Compiled & Designed by: Harkeerat Singh
Under the Guidance of: Mrs. Sakshi Jain (Department of Computer Science & Applications)
S.C.D Government College, Ludhiana
Academic Year: 2025–26
University Affiliation: Panjab University, Chandigarh

© 2025 Harkeerat Singh. All rights reserved.


This publication is intended for educational use only. No part of this book may be reproduced, distributed, or transmitted in any form or
by any means, including photocopying, recording, or other digital or mechanical methods, without the prior written permission of the
compiler, except in the case of brief quotations used for academic referencing, teaching, or educational review.
All content presented in this book has been compiled in good faith, with academic intent, under the framework of the National
Education Policy 2020 and in accordance with the official BCA syllabus of Panjab University.
All trademarks, product names, or brand names mentioned are the property of their respective owners and are used in an academic,
non-commercial context.

For permissions or inquiries, please contact:


Harkeerat3211@gmail.com
About This Book
“Mastering Problem Solving Through C - Using Notes!” is a comprehensive, learner-friendly academic resource curated
specifically for students pursuing the Bachelor of Computer Applications (BCA) under Panjab University’s latest
syllabus. This book is a detailed and structured compilation of Unit 1: Problem Solving and Fundamentals of C
Programming, presented in a modern and interactive format that resonates with the pedagogical vision of the National
Education Policy (NEP) 2020.

Crafted with precision, this book transforms traditional notes into an enriched learning experience, bridging conceptual
clarity with practical application. Each chapter is designed not just to impart theoretical understanding, but to nurture
the learner's ability to think logically, solve real-world problems, and write structured, efficient code.
This work was compiled and formatted under the valuable academic mentorship of Mrs. Sakshi Jain, whose guidance
ensured that the content remained curriculum-aligned while also expanding into broader dimensions of understanding.
Her support has been instrumental in refining this work into a reliable resource for BCA learners.

Key Highlights of This Notes-Book:


Aligned with the NEP 2020 Competency-Based Framework: Focuses on critical thinking, problem solving, and
conceptual depth over rote memorization.
Mapped to Panjab University's Latest Syllabus: Covers each topic listed in various Unit thoroughly, including the
programming process, decision tools, algorithm development, and C fundamentals and more.
Interactive and Visual: Contains flowcharts, decision tables, analogies, and exercises to foster student engagement.
Glossary and Real-World Application: Important terms are highlighted, defined, and contextualized to help learners
grasp technical vocabulary and logic.
Practice-Driven: Each chapter includes quizzes, dry-run prompts, and mini-programming problems to ensure active
learning.

About the Compiler


This book has been conceptualized, structured, and designed by Harkeerat Singh, a student of BCA at S.C.D Government
College, Ludhiana. With a passion for educational design & C.S and clarity in programming pedagogy, Harkeerat has
taken a traditional set of class notes and transformed them into an accessible, self-paced academic text.
This work represents not only a personal academic initiative but also a model for how student-led learning materials can
evolve under the spirit of NEP 2020—blending creativity, depth, and pedagogy into a single document.

Acknowledgements
This compilation would not have been possible without the support of Mrs. Sakshi Jain, who consistently inspires
students to think critically and strive for academic excellence. Her role as a mentor and reviewer of this project has
added significant value to its academic integrity and clarity.

Intended Use
This book is ideal for:
BCA students at Panjab University and affiliated colleges
Learners preparing for university exams or internal assessments
Anyone seeking to strengthen their problem-solving and C programming foundations

It may also serve as a reference guide for beginners, peer educators, or institutions looking to adopt NEP-compliant,
student-friendly content in technical education.

Let this be more than a set of notes—let it be a guide, a companion, and a reflection of the learner-centric spirit of India's
evolving education system.
Syllabus
Problem Solving Through C
Subject Code: (BCA-DSC-1 (Min)-103)

UNIT - I
Programming Process: Steps in developing of a program, Data Flow Diagram,
Decision Table, Algorithm development, Flowchart, Pseudo Code, Testing and Debugging.
Fundamentals of C Languages: History of C, Character Set, Identifiers and Keywords, Constants, Types of C Constants,
Rules for Constructing Integer, Real and character Constants, Variables, Data Types, rules for constructing variables.
Operators and Expressions: C Instructions, Arithmetic operators, Relational operators, Logical operators, Assignment
Operators, Type Conversion in Assignments, Hierarchy of Operations, Standard and Formatted Statements, Structure
of a C program , Compilation and Execution.

UNIT - II
Decision Control Structure: Decision making with IF-statement, IF-Else and Nested IFElse, The else if Clause.
Loop Control Structure: While and do-while, for loop and Nested for loop, Case Control Structure: Decision using
switch, Thegoto statement.
Functions: Library functions and user defined functions, Global and Local variables, Function Declaration, Calling and
definition of function, Methods of parameter passing to functions, recursion, Storage Classes in C.

UNIT - III
Arrays: Introduction, Array declaration, Accessing values in an array, Initializing values in an array, Single and Two
Dimensional Arrays, Initializing a 2-Dimensional Array, Memory Map of a 2-Dimensional Array, Passing array elements
to a function: Call by value and call by reference, Arrays of characters, Insertion and deletion operations, Searching the
elements in an array, Using matrices in arrays, Passing an Entire Array to a Function.
Pointers: Pointer declaration, Address operator “&”, Indirection operator “*”, Pointer and arrays, Pointers and 2-
Dimensional Arrays, Pointer to an Array, Passing 2-D array to a Function, Array of Pointers.
Dynamic Memory Allocation: malloc(), calloc(), realloc(), free() functions.

UNIT - IV
String Manipulation in C: Declaring and Initializing string variables, Reading and writing strings, String
Handlingfunctions(strlen(), strcpy(), strcmp(), strcat()).
Structures and Unions: Declaration of structures, Structure Initialization, Accessing structure members, Arrays of
structure, Nested structures, Structure with pointers, Union.
Files in C: Introduction, Opening and Closing files, Basic I/O operation on files.
Table of Contents
Unit I
Chapter 1 The Programming Process – From Idea to Execution

🧭 Overview
Before any line of code is written in C—or in any language—there is a journey of thought, design, testing, and
refinement. The programming process is the disciplined pathway that takes an abstract idea or problem and
transforms it into a working software solution.
This chapter will walk you through every stage of the programming process, helping you think like a software
engineer, and not just a coder.

🧩 1.1 What is the Programming Process?


The programming process is a step-by-step methodology that involves defining a problem, creating a solution
through logical steps (algorithms), implementing the solution in code, and testing the final product for accuracy and
efficiency.
Whether you're building a calculator, a website, or an operating system—the steps are fundamentally the same.

🪜 1.2 Steps in the Programming Process


Let’s explore the process in detail:

🔍 Step 1: Problem Definition


Before you write a single line of code, you must answer:
What problem am I solving?
Who is the user? 🧠 Pro Tip: Write down the problem in your own words to
What are the inputs, outputs, and constraints? clarify understanding.

Example: You're building a program to calculate students' grades. Inputs may include test scores, and output is the
final grade. Constraints may include a maximum number of students or subjects.

🧠 Step 2: Analyze the Problem


Break the problem into manageable parts:
What is known?
What needs to be found?
What operations are needed?

⚙️ For larger projects, use tools like Flowcharts, Data Flow Diagrams, and Decision Tables (covered later in this unit).
🔁 Step 3: Design the Algorithm
An algorithm is a finite, step-by-step procedure that tells the computer exactly what to do. It’s the logic of the
program—independent of the programming language.
📌 Forms of algorithm design:
Natural language steps
Pseudocode (human-readable logic)
Flowcharts (visual flow of logic)

🛠️ Example: If you want to sort a list of names, your algorithm may follow:
Compare adjacent names.
Swap if they’re in the wrong order.
Repeat until sorted.

🧑‍💻 Step 4: Choose the Tools


You need an environment to write and compile C code. Typically:
Compiler: GCC, Clang
IDE: Code::Blocks, Turbo C, Visual Studio Code
🔧 Install GCC via MinGW or use an online IDE like repl.it or onlineGDB. 1
📄 Step 5: Write the Code (Implementation)
Now, convert your algorithm into C syntax using variables, operators, loops, conditionals, and functions.

#include <stdio.h>
int main() { Compiler in action
int a = 5, b = 10;
printf("Sum is: %d", a + b);
return 0;
}

🧪 Step 6: Compile the Code


Use the compiler to translate your human-readable code into machine code.
If errors appear, they must be fixed before the code runs.
Pro Tip:💬 Use comments // like this or /* like
this */ to explain your code.
Common errors: missing semicolon, wrong variable name, type mismatch

⚙️ Step 7: Testing and Debugging


Run the program with different test cases:
Expected values
Edge cases (e.g., 0, negative numbers)
Invalid inputs
Use printf statements or a debugger to trace issues.

🪲 Debugging is the act of locating and fixing bugs (errors or unexpected behavior) in the code.
🚀 Step 8: Optimization
Clean up your code:
Remove redundancy
Reduce memory usage
Use efficient data structures and logic

📚 Step 9: Documentation
Add comments in code
Write a user manual or README
Create technical documentation if needed

📋 Proper documentation helps future you and your team members understand what the program does.
📦 Step 10: Deployment & Maintenance
Deploy the program to the user
Prepare installation instructions
Be ready to fix bugs and release updates

🔁 Programming is iterative: You often return to earlier steps as new needs arise.

🕰️ The Programming Process – A Fun Walk Through History


Believe it or not, programming didn’t start with laptops and code editors. It began in the 1800s with Ada Lovelace, the
first-ever programmer, who wrote an algorithm for a machine that didn’t even exist—Charles Babbage’s Analytical
Engine. Fast forward to the 1940s, programmers worked with bulky machines like ENIAC, using wires and switches to
input instructions (and yes, “debugging” meant removing real bugs from the hardware!). By the 1970s, programming
evolved into structured logic with the invention of C language by Dennis Ritchie—a major leap that laid the
foundation for modern software. Over time, the programming process became more defined: problem analysis,
design, coding, testing, debugging, and documentation. Today, we use compilers, pseudocode, flowcharts, and
algorithms—but the heart of programming remains the same: turning ideas into instructions a computer can
understand. Fun fact: most exam questions on this topic still ask you to list or explain these classic steps—so while
the tech changed, the process (and the marks!) stayed.
2
🎯 Real-World Analogy: Building a House 🏠
Programming Step House-Building Equivalent

Problem Definition Deciding what type of house to build

Algorithm Design Drawing the blueprint

Coding Laying bricks and plumbing

Compilation Checking for construction errors

Testing & Debugging Inspecting the house

Deployment Handing over the keys to the owner

📌 Key Takeaways
Programming is not just writing code—it’s problem-solving using logic and structure.
Skipping design steps (like algorithm or flowchart) can lead to buggy and inefficient programs.
Testing and debugging are as important as writing code.

📘 Mini Glossary
Algorithm: A clear set of instructions to solve a problem
Compiler: A tool that converts source code into executable code
Bug: An error in code that causes unexpected behavior
Pseudocode: Human-readable steps of an algorithm, not tied to syntax
Deployment: The process of delivering the final software to the user

🧠 Quick Quiz (Self-Practice)


1. What’s the difference between an algorithm and code?
2. What are two benefits of using pseudocode before writing the code?
3. List three types of errors that occur in programming.

🔨 Try This!
Create a program that calculates the average of 5 numbers. But before coding:
1. Write down the problem definition.
2. Design the algorithm in steps.
3. Represent it with a flowchart (draw by hand or digitally).
4. Then, code the solution in C.

🧑‍🏫 Pro Tip from a Senior Developer:


“Programming is not about knowing every syntax—it's about thinking logically and breaking down problems
effectively.”

3
Understanding Problem Solving – The Heart of
Chapter 2 Programming

🧭 Overview
Before a programmer becomes fluent in syntax or control flow, they must first master the art of problem-solving.
Programming is just one way of expressing a solution. The real power lies in the thinking that comes before the code.
This chapter dives deep into how to approach problems, techniques to break them down, and how programmers
evolve from coders to logical architects.

🔍 2.1 What is Problem Solving?


Problem solving is a structured cognitive process that involves analyzing a situation, breaking it down into
manageable parts, identifying possible solutions, selecting the most effective one, and implementing it efficiently.
In programming, it’s about translating a real-world challenge into logic that a computer can follow.

🧩 2.2 The Six Pillars of Problem Solving in Programming


Let’s explore the process in detail:

1️⃣ Understanding the Problem


You must know exactly what is being asked.
Clarify inputs, outputs, and conditions.
Ask: What do I have? What do I want?

📝 Example:
Problem: Determine whether a number is a prime.
Input: An integer n.
Output: “Prime” or “Not Prime”.

2️⃣ Gathering Information


Research relevant concepts, formulas, or logic required.
Review related problems.
Consider edge cases and exceptions.
📌 For the prime number problem: You need to know the definition of a prime (a number divisible only by 1 and
itself).

3️⃣ Breaking Down the Problem (Decomposition)


Divide the problem into smaller sub-problems.
Tackle one piece at a time.
🔨 Problem-Solving Tip:
“How do you eat an elephant? One bite at a time.”

4️⃣ Designing a Solution


Choose an algorithm or technique.
Represent it using pseudocode, flowcharts, or decision tables.

🔁 Example Pseudocode:
isPrime(n)
if n <= 1 →
return false
for i = 2 to sqrt(n)
if n % i == 0 →
return false
return true
4
5️⃣ Implementing the Solution
Write code in C based on the logic you've designed.
Keep functions modular.
Use meaningful variable names and comments.

6️⃣ Testing and Refining


Run your program with:
Normal test cases
Edge cases (like n = 1, n = 2)
Invalid inputs

🔍 If unexpected outputs arise:


Use debugging tools
Print intermediate values
Revisit your logic

💡 Real-World Analogy: The Detective Approach 🔎


Solving programming problems is like solving a mystery:
🧩 Clues = Input values
💡 Hypotheses = Algorithm ideas
🔍 Evidence testing = Test cases
✅ Final arrest = Working code!

🧠 Problem-Solving Techniques in Programming


Technique Description Example

Ask “Why?” 5 times to trace the


5 Whys Why is the output wrong?
root cause

Diagram connecting related


Mind Mapping Use for large projects
concepts

Manually execute your algorithm Useful for loops and


Dry Run
on paper conditionals

Table of variable values across


Trace Table Great for debugging
iterations

⚠️ Common Problem-Solving Challenges


Incomplete Understanding
Always clarify what is asked before attempting a solution.
Tunnel Vision
Don’t fixate on one solution too early—explore alternatives.
Skipping the Design Phase
Poor planning leads to messy, buggy code.
Ignoring Edge Cases
Test boundary conditions (e.g., 0, negative numbers).

5
🧾 Sample Problem Breakdown
🧩 Problem: Write a C program to find the factorial of a number.
📋 Algorithm:
1. Input number n
2. Initialize fact = 1
3. Repeat from 1 to n:
fact = fact * i
4. Output fact

✅ C Code:
#include <stdio.h>
int main() {
🧪 Try This!
int n, fact = 1;
printf("Enter a number: ");
🧠 Problem: Build a C program to find
the sum of digits of a number.
scanf("%d", &n);
Before jumping into code:
for (int i = 1; i <= n; i++) { Break it down into steps.
fact *= i; Write the pseudocode.
} Implement in C.
printf("Factorial of %d is %d\n", n, fact); Test for single-digit, multi-digit, and
return 0; zero.
}

🧠 Quick Quiz (Self-Practice)


1. What are the main phases of problem solving?
2. What is the purpose of “dry running” your code?
3. List three strategies to test if your program is working correctly.

📘 Mini Glossary
Algorithm: Step-by-step logical process
Dry Run: Manually simulating program flow
Edge Case: Input that tests the limits of the program
Debugging: Identifying and removing errors
Decomposition: Breaking down a problem into smaller parts

Pro Tip: “A good programmer is not one who never makes mistakes, but one who identifies and corrects them
efficiently.”

6
Data Flow Diagrams (DFDs) –
Chapter 3 Visualizing System Logic

🧭 Overview
When planning a software system, especially before coding, it’s essential to understand how data flows through the
system. A Data Flow Diagram (DFD) is one of the most effective tools for this purpose.
Think of a DFD as the Google Maps of a system’s data flow—showing what moves where, from whom, to whom, and
how it’s processed.

🔍 3.1 What is a Data Flow Diagram?


A Data Flow Diagram (DFD) is a graphical representation of how data moves through an information system. It
illustrates the:
Flow of data between processes
Interaction with external entities
Storage in data stores
It helps in system analysis, design, and documentation, making it easier for developers and stakeholders to
understand the underlying structure and behavior of a system.

📘 DFD ≠ Flowchart. A flowchart shows control flow; a DFD shows data flow only.
🧱 3.2 Key Components of a DFD
Component Symbol Description

Process 🟢 Circle / Oval Represents an activity that


transforms inputs into outputs

Data Store 📦 Open Rectangle A place where data is stored


(e.g., database, file)

A source or destination of data


External Entity 🧍 Rectangle outside the system (e.g., user,
sensor)

Data Flow ➡️ Arrow Shows the direction in which


data moves

💬 Pro Tip: Every data flow must start and end at a process.
🔁 Example:
Let’s take a simple ATM system. Here’s how its DFD might look:
📌 Entities:
User
📌 Processes:
Authenticate User
Process Transaction
📌 Data Stores:
Account Database

7
📌 Flows:

Card Data Authenticate User

Auth Result User

Withdrawal Request Process Transaction

🧱 3.3 DFD Levels


DFDs are layered—you start from a big-picture view (Level 0) and drill down into details.
🔹 Level 0: Context Diagram
Shows the entire system as a single process.
Displays interaction with external entities only.
🔹 Level 1: Decomposition Diagram
Breaks the system into major sub-processes.
Shows flow between these processes and data stores.
🔹 Level 2+: Detailed Views
Continues breaking down each Level 1 process into smaller tasks.

📌 Think of it like zooming into a city on a map—Level 0 is the continent, Level 1 is the country, Level 2 is the city,
etc.

📈 3.4 Purpose and Benefits of DFDs


✅ Helps:
Understand what data enters and leaves the system
Clarify the logic of processes
Identify bottlenecks or redundancies
Serve as a blueprint for system design and coding

⚖️ 3.5 Advantages vs. Disadvantages


✅ Advantages ❌ Disadvantages
Process 🟢 Circle / Oval
Data Store
📦 Open
Rectangle

External Entity 🧍 Rectangle Logic


Design
Data Flow ➡️ Arrow

🔍 3.6 DFD vs. Flowchart – What's the Difference?


Flow

7
✅ Advantages ❌ Disadvantages
DFD vs. Flowchart
Process 🟢 Circle / Oval
Data Store 📦 Open Rectangle
External Entity 🧍 Rectangle
Data Flow ➡️ Arrow

🧠 Sample Scenario – DFD for Library System


Process: Issue Book
Entities: Student, Librarian
Data Store: Book Database
🧾 Data Flow:
→ →
1. Student Request Issue Librarian
→ →
2. Librarian Search Book Book Database
→ →
3. Book Issued Book Student

🧪 Try This!
Draw a Level 0 and Level 1 DFD for the following system:
Online Food Ordering App
Entities: Customer, Restaurant
Data Store: Order Records, Menu
Processes: Place Order, Make Payment, Update Inventory

📘 Mini Glossary
DFD: Data Flow Diagram – shows flow of data between processes
Entity: External user/system interacting with the program
Process: Activity that transforms data
Data Store: A location where data is held permanently or temporarily
Context Diagram: A top-level (Level 0) DFD showing only external entities and one process

🧠 Quick Quiz (Self-Practice)


1. What are the four main components of a DFD?
2. How is a Level 1 DFD different from Level 0?
3. Why is a DFD better than a flowchart for system design?

🎓 Pro Tip: “If you can draw your system as a clean DFD, you’ve already solved half of your programming logic.”

8
Decision Tables – Tabular Thinking
Chapter 4 for Clear Logic

🧭 Overview
Programming is filled with decisions: If this happens, then do that. As the number of possible conditions increases,
writing out nested if-else logic becomes messy and error-prone.
A Decision Table offers a structured and visual way to model such logic. It is widely used in areas like banking
systems, form validations, billing, and any place where multiple conditions affect the result.

🧩 4.1 What is a Decision Table?


A Decision Table is a tabular representation of all possible conditions and the corresponding actions to be taken for
each combination.
Think of it as a truth table for actions. It shows clear mappings between "what is" and "what should be done."
📘 A Decision Table is also known as a Cause-Effect Table.

🔍
4.2 Components of a Decision Table
A Decision Table typically has four main parts:

Section Description

Lists all the input conditions (Yes/No,


Condition Stub
True/False)

Represents all combinations of the


Condition Entries
conditions (rules or scenarios)

Lists all the possible actions the system


Action Stub
can take

Maps which action(s) should be taken


Action Entries
under which condition combinations

🧾 4.3 Format of a Decision Table


Here’s the general structure:
-------------------------------------------------
| Conditions | Rule 1 | Rule 2 | Rule 3 |
-------------------------------------------------
Quick Check:
| Condition A | Y | Y | N |
| Condition B | N | Y | Y | What do the columns in a
------------------------------------------------- decision table represent?
| Actions | | | |
-------------------------------------------------
| Action 1 | ✓
| | | ✓
| Action 2 | | | ✓ |
-------------------------------------------------

📌 Each "Rule" represents one possible scenario (combination of Yes/No conditions).

🧠 4.4 Example: ATM Withdrawal Rules


Let’s say an ATM should allow cash withdrawal if:
The user is authenticated.
The account balance is sufficient.
9
🔹 Step 1: Define Conditions & Actions
Conditions Description

C1: Is user valid? Y/N

C2: Is balance enough? Y/N

Actions Description

A1: Dispense cash ✔


A2: Show error message ✔
🔹 Step 2: Create the Table
-----------------------------------------------------------
| Conditions | Rule 1 | Rule 2 | Rule 3 | Rule 4 |
-----------------------------------------------------------
| User Valid (C1) | Y | Y | N | N |
| Balance Sufficient (C2)| Y | N | Y | N |
-----------------------------------------------------------
| Actions | | | | |
-----------------------------------------------------------
| Dispense Cash (A1) | ✓| | | |
| Show Error (A2) | | | ✓ | ✓ | ✓
-----------------------------------------------------------
🎯 Rule 1 is the only scenario where cash is dispensed. All others result in an error.

⚖️ 4.5 Advantages of Decision Tables


✅ Benefit Explanation

Makes complex conditions easy Pro Tip:


Clarity
to understand "When studying decision
tables, focus on the logic,
Quick Check: Ensures all possible scenarios
Name one key Completeness not the layout.”
are covered Always count the rules
advantage of using
as 2ⁿ, where n is the
decision tables. Consistency Minimizes logic contradictions
number of conditions—
so you don’t miss any
Helps QA/testers generate
Test Case Design combinations!
robust test cases

Can be reviewed by stakeholders


Non-Programmer Friendly
or business analysts

🧱 4.6 Types of Decision Tables

10
Type Description

Conditions are binary (Yes/No or


Limited Entry
True/False)

Conditions can have multiple


Extended Entry values (e.g., <1000, 1000–5000,
>5000)

Multiple tables linked for


Linked Decision Table
complex systems

Based on whether all condition


Balanced/Unbalanced
combinations are included

Type Description

🔧 4.7 Converting Decision Table to Code


Once your logic is finalized, it's easy to convert it into nested if-else or switch-case statements.

🔹 Example (From ATM Rule 1):


if (userValid == 1 && balance >= amount) {
printf("Dispensing Cash...\n");
} else {
printf("Transaction Failed.\n");
}

Example
To implement a decision table in C, you can use conditional statements (like if, else if, and switch) based on the
conditions:

#include <stdio.h>
void checkLoanApproval(int creditScore, int income) {
if (creditScore >= 700 && income >= 50000) {

→ To Code is a clean, traceable


printf("Loan Approved\n");
} else if (creditScore >= 700 && income < 50000) { From Table
printf("Loan Review Needed\n"); process.
} else if (creditScore < 700 && income >= 50000) {
printf("Loan Review Needed\n");
} else {
printf("Loan Denied\n");
}
}

int main() {
13
int creditScore = 750; // Example input
int income = 45000; // Example input
checkLoanApproval(creditScore, income);
return 0;
}
11
🧠 When to Use Decision Tables?
Use decision tables when:
You face multiple conditions influencing multiple actions.
You want to avoid deeply nested if-else blocks.
You need clear documentation or audit trails of logic.

Example:
A decision table

🧪 Try This!
🎯 Create a Decision Table for the following scenario:
Online Food Delivery App:
Conditions:
Is the user logged in?
Is the delivery location within service area?
Is the payment successful?
Actions:
Confirm Order
Show Service Unavailable
Show Payment Error

📘 Mini Glossary
Decision Table: A structured table listing conditions and corresponding actions
Rule: One complete combination of input conditions
Action Stub: Part of the table showing possible outcomes or decisions
Limited Entry: Table where condition values are binary
Balanced Table: Covers all possible condition combinations

🧠 Quick Quiz (Self-Practice)


1. What are the four parts of a Decision Table?
2. How does a Decision Table help reduce logic errors?
3. Create a 2-condition, 3-rule Decision Table for a “login” feature.

Pro Tip:
“When your if-else logic begins to look like a tangled web, switch to a decision table—it’s like clearing fog from your
logic.”

11
11

You might also like