Last reviewed 16 Sept 2026 · 10 min read
Problem solving with computers
- Understand the problem (inputs, required outputs, constraints).
- Design a solution — algorithm, flowchart or pseudocode.
- Code the solution in a programming language.
- Test and debug.
- Document and maintain.
Algorithms
An algorithm is a finite, step-by-step set of well-defined instructions to solve a problem.
Characteristics of a good algorithm
| Property | Meaning |
|---|---|
| Input | Zero or more well-defined inputs |
| Output | At least one output |
| Definiteness | Each step clear and unambiguous |
| Finiteness | Terminates after a finite number of steps |
| Effectiveness | Each step basic enough to be carried out |
| Generality | Applies to a class of problems |
Example algorithm — area of a rectangle
- Start
- Read length L and breadth B
- Area ← L × B
- Print Area
- Stop
Pseudocode
Informal, language-independent description using programming-like keywords:
BEGIN
READ L, B
AREA = L * B
PRINT AREA
END
Algorithm efficiency — time and space complexity (Big-O notation, e.g. linear search O(n), binary search O(log n)).
Flowcharts
A flowchart is a graphical representation of an algorithm using standard symbols.
| Symbol | Shape | Use |
|---|---|---|
| Terminal | Oval / rounded rectangle | Start and stop |
| Input/Output | Parallelogram | Read input, display output |
| Process | Rectangle | Calculations, assignments |
| Decision | Diamond | Yes/No or True/False branching |
| Flow line | Arrow | Direction of flow |
| Connector | Small circle | Joins parts of a flowchart on the same page |
| Off-page connector | Pentagon (home-plate shape) | Continuation on another page |
| Predefined process | Rectangle with double vertical sides | Subroutine/function |
| Document | Rectangle with wavy base | Printed output |
Rules
- Flow generally top to bottom, left to right; one start and one stop.
- Decision symbols have one entry and two (or more) exits, labelled.
- Flow lines should not cross unnecessarily; use connectors.
Advantages and limitations
- Advantages: easy to understand and communicate logic; helps debugging and documentation.
- Limitations: difficult to draw/modify for complex programs; not directly executable.
Example — check whether a beam passes deflection
Start → Input actual deflection δ and span L → Process: allowable = L/250 → Decision: δ ≤ allowable? → Yes: print "Safe" / No: print "Revise section" → Stop
Decision tables
Tabular representation of conditions and corresponding actions — useful when many combinations exist (e.g. concrete exposure condition and minimum grade).
Programming paradigms
| Paradigm | Features | Languages |
|---|---|---|
| Procedural (structured) | Sequence of procedures/functions; top-down design; sequence, selection, iteration | C, FORTRAN, Pascal |
| Object-oriented (OOP) | Classes and objects; encapsulation, inheritance, polymorphism, abstraction | C++, Java, Python, C# |
| Functional | Functions as values, immutability | Haskell, Lisp; features in Python |
| Logic | Facts and rules | Prolog |
| Scripting / event-driven | Automation, GUIs, web | Python, JavaScript, VBA |
Structured programming constructs: sequence, selection (if/switch), iteration (loops) — sufficient for any algorithm.
Program development life cycle
Problem definition → analysis → design (algorithm/flowchart) → coding → testing and debugging → documentation → deployment → maintenance.
Errors and debugging
| Error type | Detected | Example |
|---|---|---|
| Syntax (compile-time) error | By compiler — violates language grammar | Missing semicolon, misspelled keyword |
| Runtime error | During execution — program crashes | Division by zero, invalid memory access, file not found |
| Logical error | Program runs but gives wrong output — hardest to find | Using wrong formula (e.g. πD instead of πD²/4) |
| Linker error | Missing function definitions/libraries | Undefined reference |
Debugging — finding and fixing bugs (breakpoints, tracing, test cases, print statements).
C programming basics
- C was developed by Dennis Ritchie at Bell Laboratories in 1972 (used to rewrite Unix).
- Middle-level, procedural, compiled language; portable, efficient; basis of C++, Java, etc.
- Case-sensitive; statements end with semicolon (;).
Structure of a C program
#include <stdio.h> /* preprocessor directive: header file */
#define PI 3.14159 /* symbolic constant */
int main(void) /* execution starts at main() */
{
float d, area; /* variable declarations */
printf("Enter pipe diameter (m): ");
scanf("%f", &d); /* input */
area = PI * d * d / 4; /* processing */
printf("Area = %.4f m2\n", area); /* output */
return 0;
}
Compilation process
Source code (.c) → preprocessor (handles #include, #define) → compiler (object code) → linker (links libraries) → executable → loader runs it.
Tokens
| Token | Examples |
|---|---|
| Keywords (reserved words; 32 in standard C89) | int, float, char, double, if, else, for, while, do, switch, case, break, continue, return, void, struct, const |
| Identifiers | Names of variables/functions — start with letter or underscore; letters, digits, underscore; no spaces or keywords |
| Constants | 10, 3.14, 'A', "text" |
| Operators | + - * / % etc. |
| Special symbols | { } ( ) [ ] ; , |
Data types (typical sizes on modern 32/64-bit systems)
| Type | Typical size | Format specifier | Example |
|---|---|---|---|
char |
1 byte | %c |
'A' |
int |
4 bytes | %d |
25 |
float |
4 bytes (≈ 6–7 significant digits) | %f |
3.14 |
double |
8 bytes (≈ 15 significant digits) | %lf |
2.718281828 |
long, short, unsigned |
Modifiers | %ld, %u |
|
void |
No value | — | Function returning nothing |
(Sizes are implementation-dependent; use sizeof to check.)
Operators
| Category | Operators |
|---|---|
| Arithmetic | + - * / and % (modulus — remainder, integers only) |
| Relational | < > <= >= == != |
| Logical | && (AND), || (OR), ! (NOT) |
| Assignment | = += -= *= /= |
| Increment/decrement | ++, -- (prefix and postfix) |
| Conditional (ternary) | condition ? a : b |
| Bitwise | & (AND), | (OR), ^ (XOR), ~ (NOT), <<, >> (shifts) |
| Special | sizeof, & (address), * (pointer), , |
- Integer division truncates:
7/2= 3;7.0/2= 3.5. - Precedence (high to low, simplified):
()→ unary (! ++ --) →* / %→+ -→ relational → equality →&&→||→ ternary → assignment.
Control structures
/* if–else */
if (fck >= 25)
printf("Grade OK\n");
else
printf("Grade not OK\n");
/* switch */
switch (zone) {
case 2: Z = 0.10; break;
case 3: Z = 0.16; break;
case 4: Z = 0.24; break;
case 5: Z = 0.36; break;
default: printf("Invalid zone\n");
}
/* for loop */
for (i = 1; i <= 10; i++)
sum = sum + i;
/* while loop — condition checked first (entry-controlled) */
while (error > 0.001) { /* iterate */ }
/* do–while — executes at least once (exit-controlled) */
do { /* read value */ } while (value < 0);
- break exits a loop/switch; continue skips to the next iteration.
Arrays and strings
- Array — collection of same-type elements with a common name:
float load[5];indices 0 to 4. - 2D array:
int m[3][3]; - String — character array ending with null character
'\0':char name[20] = "Bridge";— functions in<string.h>:strlen,strcpy,strcat,strcmp.
Functions
- Reusable blocks: declaration (prototype), definition, call.
- Library functions (
printf,sqrtin<math.h>) and user-defined functions. - Call by value (copy passed) vs call by reference (address passed using pointers).
- Recursion — function calling itself (e.g. factorial).
Pointers (introduction)
- A pointer stores the memory address of a variable:
int *p; p = &x;→*pgives the value of x. - Used for arrays, dynamic memory (
malloc,free), call by reference, data structures.
Other features
Structures (struct grouping different types — e.g. a beam record with span, width, depth), unions, file handling (fopen, fprintf, fscanf, fclose), preprocessor macros.