Problem Solving with Computer Programming
Problem Solving with Computer Programming
Problem Solving
using Computer
Programming
LBS MCA CRASH COURSE 2025
01
Introduction to Problem
Solving
Understanding the Problem-Solving Process
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
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
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()
🔹 Structure of a Function
1. Function Declaration
2. Function Definition
3. Function Call
🔹 Types Based on Use
Type Example
🧠 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
✅ Can catch compile-time errors, not logical errors Step through the code
Just another word for starting/executing a program Find logical or runtime errors
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
Data and functions are separate. Data and functions are encapsulated together in classes.
Example: C language
🟢 So, what’s the big difference?
Procedural OOP
🔹 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
📌 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.
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.