C Language Notes-1
C Language Notes-1
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
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.
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.
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.
⚙️ 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.
#include <stdio.h>
int main() { Compiler in action
int a = 5, b = 10;
printf("Sum is: %d", a + b);
return 0;
}
🪲 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.
📌 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
🔨 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.
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.
📝 Example:
Problem: Determine whether a number is a prime.
Input: An integer n.
Output: “Prime” or “Not Prime”.
🔁 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.
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.
}
📘 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.
📘 DFD ≠ Flowchart. A flowchart shows control flow; a DFD shows data flow only.
🧱 3.2 Key Components of a DFD
Component Symbol Description
💬 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
📌 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.
7
✅ Advantages ❌ Disadvantages
DFD vs. Flowchart
Process 🟢 Circle / Oval
Data Store 📦 Open Rectangle
External Entity 🧍 Rectangle
Data Flow ➡️ Arrow
🧪 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
🎓 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.2 Components of a Decision Table
A Decision Table typically has four main parts:
Section Description
Actions Description
10
Type Description
Type Description
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) {
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
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