LBS MCA CRASH COURSE 2025
Problem Solving
using Computer
Programming
LBS MCA CRASH COURSE 2025
01
Introduction to Problem
Solving
Understanding the Problem-Solving Process
Definition of Problem Steps in Problem Solving Importance of Programming
Solving The steps typically involve in Problem Solving
Problem solving is the process defining the problem, Programming provides tools
of identifying a challenge or generating alternatives, and methodologies to
issue and working evaluating options, and automate solutions, allowing
systematically to find a implementing solutions, for efficiency, precision, and
solution, utilising critical followed by reviewing the the ability to tackle complex
thinking and reasoning skills. outcomes for effectiveness. problems systematically.
Steps in Problem Solving
1. Understanding the Problem
a. Identify inputs and expected outputs.
2. Analyzing the Problem
a. Break the problem into smaller components.
3. Developing an Algorithm
a. Step-by-step procedure to solve the problem.
4. Writing the Program
a. Translate the algorithm into C code.
5. Testing and Debugging
a. Run the program with sample data and fix any errors.
6. Documentation
a. Add comments and maintain clarity in code.
LBS MCA CRASH COURSE 2025
02
Basics of C
Programming
Basic Structure of C
Prorgamming
Structure of C Programming
1.Documentation
2.Link
3.Definition
4.Global Declaration
5.Main Function
6.Subprograms
LBS MCA CRASH COURSE 2025
03
Tokens
Tokens in C
Smallest elements of code:
1. Keywords (e.g., if, else, for)
2. Identifiers (variable names)
3. Constants (fixed values)
4. Operators (+, -, *, /)
5. Special Characters (;, {}, [], etc.)
6. Strings ("Hello")
Keywords | Reserved words
Words having fixed meanings
Eg: int, auto, break, char, etc.
always in lowercase
32 keywords in c
Identifiers
Collection of characters used for naming
variables, functions etc.
Rules for creating identifiers
st
1 character must be alphabet (or) underscore
following can be letters, digits or _
special characters not allowed except _
can be of any length (ANSI C recognized 31
characters)
keywords cannot be used
Eg: sum, sum_of_numbers, any2, _int, FOR
Constants
Constants are fixed values that do not change during
the execution of a program.
Types of Constants:
Numeric Constants
Integer constants
Floating-point constants
Character Constants
String Constants
Operators
Arithmetic Operators: +, -, *, /, %
Unary Operators: ++, --, -, sizeof(type)
Relational: ==, !=, <, >, <=, >=
Logical: &&, ||, !
Assignment: =, +=, -=, etc.
Conditional/ ternary: condition ? true_expr : false_expr
Bitwise: &, |, <<, >>
Increment and decrement operator
❓ Sample Questions (Concept Check)
int a = 10;
printf("%d", ++a);
Output: 11
int a = 10, b;
b = a++;
printf("%d %d", a, b);
Output: 11 10
int x = 5;
printf("%d", x--);
Output: 5 (but x becomes 4 afterward)
Logical Operators
Logical operators are used to combine or invert
conditions. They return 1 (true) or 0 (false).
Conditional / Ternary Operator
The ternary operator provides a shorthand way to write
simple if-else statements.
Bitwise Operators in C
Bitwise operators work at the binary level — they
perform operations bit by bit on integers..
LBS MCA CRASH COURSE 2025
04
Control Structure
Control Structure
Control structures direct the flow of execution in a
program.
1) Branching
2) Looping
simple IF
while
IF-ELSE
do-while
ELSE-IF ladder
for
switch statement
goto statement
1) Branching
2) Looping
LBS MCA CRASH COURSE 2025
05
Functions
Modular Programming
●Dividing a large problem into sub-problems and developing
subprogram for each of the sub-problems.
Modular Programming
🔹 Standard Library Functions
Functions in C: Predefined functions provided by C,
stored in header files.
Example: printf(), sqrt()
Standard Library Function
🔹 User-Defined Functions
Functions created by the
programmer to perform specific
tasks.
User-defined Funciton
Example: void greet(),
int add(int a, int b)
✅ Standard Library Functions in C
These are predefined functions provided by C to
perform common tasks. Function Purpose Header File
🔹 What Are They? printf() Prints output to screen <stdio.h>
Built-in functions included with C compilers
scanf() Takes input from user <stdio.h>
Save time — no need to write common functions
from scratch sqrt() Calculates square root <math.h>
🔹 Usage strlen() Returns length of string <string.h>
Each function is defined in a specific header file.
malloc() Allocates memory <stdlib.h>
You must #include the header to use the function.
✅ User-Defined Functions in C
These are functions created by the programmer to
perform specific tasks.
🔹 Why Use Them?
Breaks the program into smaller, manageable parts
Increases reusability and readability
Helps in debugging and testing
🔹 Structure of a Function
1. Function Declaration
2. Function Definition
3. Function Call
🔹 Types Based on Use
Type Example
No return, no parameters void greet()
Return, no parameters int getNumber()
Return with parameters int add(int a, int b)
No return, with parameters void display(int a)
✅ Parameter Passing in C ✅ Parameter Passing in C
🔹 1. Pass by Value (✔️ Supported in C) 🔹 2. Pass by Reference (❌ Not directly supported in C)
Value of actual parameter is copied to the formal parameter Address of actual parameter is passed
Changes made in the function do not affect the original value Changes made in the function affect the original value
Actual and formal parameters use different memory locations Same memory location is used for both
✅ Can be simulated using pointers:
🧠 Note:
Actual Parameter: Value passed to the function
Formal Parameter: Variable inside function receiving the value
PYQ
2024
✅Explanation:
🔹 1. int a, b;
Both a and b are declared but not initialized
(undefined values initially).
🔹 2. if (a = 0)
⚠️ This is not a comparison, it's an assignment.
You are assigning 0 to variable a.
This means:
a = 0 sets a to 0
The expression a = 0 evaluates to 0
if (0) is false in C
🔹 3. So what happens?
Since the condition is false, the else block runs.
✅Explanation:
a) Compiling
Translates your C code (source code) into machine code (object d) Debugging ✅
file) The process of identifying and fixing
Detects only syntax errors like missing semicolons, undeclared errors
variables, etc. You use a debugger (e.g., GDB) to:
✅ Can catch compile-time errors, not logical errors Step through the code
b) Running Monitor variables
Just another word for starting/executing a program Find logical or runtime errors
You run a program after compilation 🛠️ Only debugging helps detect
❌ Does not help detect errors directly errors that:
c) Executing The compiler doesn't catch
Means the same as "running" — the program is being carried out Don’t cause the program to crash but
❌ Errors may occur during execution, but execution itself give wrong output
doesn’t detect them
2023
🔍 Explanation: b) Object-Oriented Programming (OOP)
a) Procedural Programming
Code is organized into objects (real-world entities).
Code is organized into functions (procedures).
Focuses on how things are done (step-by-step instructions). Focuses on what things are (modeling data and behavior).
Data and functions are separate. Data and functions are encapsulated together in classes.
Example: C language
🟢 So, what’s the big difference?
Procedural OOP
Like a to-do list Like smart building blocks
Focuses on steps Focuses on parts (objects)
Less reusable Easy to reuse parts
✅ Object-Oriented Programming (OOP) Concepts in C++
OOP models real-world things as objects that have data and behavior.
🔹 1. Class
Blueprint or template for creating objects
Defines what data (variables) and functions (methods) an object will have
✅ Object-Oriented Programming (OOP) Concepts in C++
OOP models real-world things as objects that have data and behavior.
🔹 2. Object
A real thing created from a class
Has its own copy of the class's data and functions
✅ Object-Oriented Programming (OOP) Concepts in C++
OOP models real-world things as objects that have data and behavior.
🔹 3. Encapsulation
Keeping data safe inside a class
Only allow access through methods (like drive())
🔹 4. Inheritance
A class can inherit from another class
Reuse code and add new features
✅ Object-Oriented Programming (OOP) Concepts in C++
OOP models real-world things as objects that have data and behavior.
🔹 5. Polymorphism
Same function works in different ways for different objects
🔹 6. Abstraction
Hides complex details
Shows only what is necessary
🧠 Think of a class as a mold, and an object as
the chocolate made from that mold 🍫
🔍 Explanation of All Options:
🅰️ a) Compiler ✅
A compiler is a special program that translates code
written in a high-level programming language (like C or
C++) into machine-level language (binary code) that the
computer's processor can understand.
📌 Example:
C code → compiled by GCC → becomes an executable
machine code file
🅱️ b) Macros ❌
Macros are code shortcuts or preprocessor directives in C
(like #define) used to substitute text before compilation.
They do not translate code to machine language — they
just make writing code easier.
🅲 c) Operating System ❌
An Operating System (OS) is system software (like
Windows or Linux) that manages hardware and runs
programs. It does not convert code — it just runs the
program after it has already been compiled.
🅳 d) Loader ❌
A loader is part of the OS that loads compiled programs
into memory so they can be run.
It doesn't convert code — it just places the already
compiled machine code into RAM for execution.
🔍 Explanation:
In C programming, when you pass an array to a function, you're
actually passing the address of the first element of the array —
not a copy of the entire array.
That means:
🔁 Any changes made inside the function can affect the original
array.
💡 This is called Call by Reference.
Even though C doesn’t support call-by-reference for normal
variables directly, it behaves like call-by-reference for arrays.
LBS MCA CRASH COURSE 2025
06
Array
✅ Array in C (One-Dimensional)
An array is a collection of elements of the same
data type, stored under one name.
Each element is accessed using an index (subscript)
in square brackets.
Index starts from 0.
Useful for storing and processing multiple values
efficiently.
Why Use Arrays?
Easier to manage many similar values (e.g.,
marks of 100 students).
Data is stored in contiguous memory
locations.
Initialization of Array
1st approach
int Mark[5] = {25,35,30,45,40};
2nd approach
int Mark[ ] = {25,35,30,45,40};
3rd approach
int Mark[5] = {25,35,30};
4th approach
for(int i=0;i<5;i++)
{
scanf(“%d”,&Mark[i]);
}
Runtime and compile time
polymorphism explain
🔹 2. Runtime Polymorphism
✅ Two Types of Polymorphism in C++ (also called Dynamic Polymorphism)
✅ Happens when the function to call is decided at runtime.
🔹 1. Compile-Time Polymorphism
(also called Static Polymorphism) Requires:
✅ Happens when the function to call is decided at compile time. Inheritance
A virtual function in the base class
⭐ Function Overloading A base class pointer or reference
Same function name, but different parameters in the same class.