Fundamentals of Programming Study Notes
Flowcharting, Algorithms, and Systematic Problem Solving
Algorithms:
An algorithm is a structured sequence of step-by-step instructions designed to solve a specific problem or perform a task.
Algorithms provide a systematic framework to decompose complex problems, ensuring clarity, logical correctness, and computational efficiency.
Flowcharts:
A flowchart is a visual representation of an algorithm or process using standardized geometric symbols connected by flowlines.
Graph Structure Fundamentals:
In visual problem modeling, diagrams often rely on graph concepts consisting of Nodes/Vertices (representing entities or states) connected by Edges (representing relationships or transitions).

Standard Flowchart Symbols:
Terminal (Oval / Rounded Rectangle): Indicates the Start or End point of a program or sub-process.
Process (Rectangle): Represents an action step, arithmetic operation, or data manipulation.
Decision (Rhombus / Diamond): Represents a conditional evaluation branching into alternative paths (e.g., Yes/No or True/False).
Input/Output (Parallelogram): Denotes input receiving operations or output display processes.
On-Page Connector (Circle / Pentagon): Represents a jump or connection point within the same diagram page.
Flowline (Arrowed Line): Dictates the directional flow of control.
Algorithm Example 1: Determining if a Number is Even or Odd:
Start: Initiate execution.
Preparation: Initialize necessary variables.
Input Number: Read integer input from the user.
Process: Compute remainder using modulo operation:
Decision: Is ?
If Yes: Branch to print "Even".
If No: Branch to print "Odd".
Print Even: Output that the value is even.
Print Odd: Output that the value is odd.
End / Stop: Terminate process.

Algorithm Example 2: Student Grade Pass/Fail Evaluation:
Start: Begin process.
Input Grade for Quiz: Receive numerical grade for quiz.
Input Grade for Activity: Receive numerical grade for activity.
Input Grade for Exam: Receive numerical grade for exam.
Calculate Average Grade: Compute average using the formula:
Decision: Is ?
If Yes: Display "PASSED".
If No: Display "FAILED".
Stop: Terminate algorithm execution.

Core Characteristics of an Algorithm:
Finiteness: An algorithm must always terminate after a finite number of steps.
Definiteness: Each step must be precisely defined and unambiguous.
Effectiveness: Operations must be sufficiently basic that they can be performed accurately and in finite time.
Efficiency: The algorithm must optimize resource usage, such as processing time and memory execution.
Key Benefits of Flowcharting:
Easy to Understand: Simplifies logical tracking through pictorial representation.
Visual Representation: Provides a clear macro view of system operations.
Improved Communication: Facilitates logic sharing across multi-disciplinary teams.
Debugging: Assists in isolating syntax and logical branching errors prior to coding.
Documentation: Serves as a blueprint for system maintenance and updates.
Software Development Life Cycle (SDLC)
Definition:
The Software Development Life Cycle (SDLC) is a structured framework that defines the sequential phases of software production to ensure high-quality software, delivery within deadlines, and effective resource management.
Sequential Stages of SDLC (Waterfall Perspective):
Systems Requirements: Gathering functional and technical requirements from stakeholders.
Analysis: Analyzing feasibility, system constraints, and input/output requirements.
Design: Architecting system workflows, databases, flowcharts, and interface layouts.
Coding: Writing source code using programming languages like C based on design specs.
System Test: Executing test protocols to uncover syntax errors, runtime exceptions, and logical bugs.
Maintenance: Updating, patching, and modifying software post-deployment to adapt to user feedback or environment changes.

Importance of SDLC in Problem-Solving:
Provides a Structured Approach to handle complex projects.
Establishes Clarity and Focus for project requirements.
Enables systematic Risk Management throughout the development cycle.
Ensures rigorous Quality Assurance prior to deployment.
Generates comprehensive project Documentation.
Encourages structured User Involvement.
Offers systematic Flexibility for Changes.
Guarantees long-term Post-Implementation Support.
Evolution of Programming Languages and C Fundamentals
Evolutionary Paradigms of Programming Languages:
Early Languages (Machine Code & Assembly): Hardware-dependent languages written in binary or low-level mnemonic opcodes.
High-Level Languages (Fortran, COBOL): Introduced mathematical notation and business-oriented abstractions, improving readability and usability.
Structured Programming (C): Introduced procedural modularity, block structures, efficient memory pointer access, and control structures.
Object-Oriented Languages (C++, Java): Enhanced code modularity, encapsulation, inheritance, and reusability.
Scripting Languages (Python, JavaScript): Optimized for rapid development, duck typing, automated memory management, and cross-platform versatility.
Origins and Significance of the C Language:
Developed in the early 1970s at Bell Labs by Dennis Ritchie.
Combines the speed and low-level hardware control of assembly language with the structured control flow of high-level languages.
Serves as the foundation for operating systems (such as UNIX and Linux), compilers, embedded systems, and modern object-oriented computing paradigms.
The C Translation and Build Process:
Source File: Human-readable source code written in files ending with
.c.Preprocessing: The preprocessor evaluates directives starting with
#(e.g.,#include,#define), expands macros, and strips comments to yield a preprocessed output file (.ifile).Compilation: The compiler translates preprocessed high-level C code into platform-specific assembly instructions (
.sfile).Assembly: The assembler converts assembly code into relocatable machine object code (
.oor.objfile).Linking: The linker resolves symbol references, links runtime startup files along with compiled library functions, and outputs the binary executable file (
.exeor.out).Program Execution: The Operating System loads the executable into memory, sets up stack/heap memory, and transfers control to the entry point.

Basic Structure and Style of a C Program
Importance of Programming Style:
C is free-format regarding whitespace and indents; however, structured style is essential for code maintainability.
Manageability: Organized programs are easy to modify as codebases scale.
Understanding: Descriptive identifiers assist developers in identifying variable roles.
Readability: Consistent indentation and alignment make logic tracing and debugging faster.
Core Axiom: .
Comparing Unformatted vs. Formatted C Code:
Unformatted Code:
c int main(){int age;printf("Age:");scanf("%d",&age);return 0;} Formatted Code:
c int main() { int age; printf("Age: "); scanf("%d", &age); return 0; }
Anatomy of a C Source File:
Preprocessor Directive: Informs the preprocessor to load standard header files.
main()Function: Mandatory entry point function.Variable Declarations: Allocates memory locations with designated data types.
Input/Output Statements: Communicates with the user via standard input/output streams.
Successful Program End: Returns an integer code (
return 0;) to the OS.
The
main()Function Execution Flow:Execution always starts at
main(), regardless of its physical line position in the source file.The empty parentheses
()signify thatmain()takes no parameters in its basic form.Execution lifecycle: .
Comments in C:
Notes embedded within code that are ignored by the compiler.
Single-line Comment: Starts with
//and extends to the end of the line.c // This is a single-line comment printf("Hello"); Multi-line Comment: Enclosed within
/*and*/, spanning across single or multiple lines.c /* This is a multi-line comment that can span multiple lines. */ printf("Hello"); Best Practice: Comments should explain the intended logic or rationale of code rather than repeating obvious operational syntax.
Preprocessor Directives and Macro Constants:
Directives begin with
#and are processed before compilation.#include <stdio.h>: Includes the Standard Input Output library containing definitions for functions likeprintf()andscanf().#define: Creates symbolic constants or macro replacements across source code prior to compilation. ```cinclude
define STUD_NO "204-1234
"
define CONTACT "09651234567
"
int main() { printf(STUD_NO); printf(CONTACT); return 0; } ```
Naming Convention: Symbolic constants created via
#defineshould be written in UPPERCASE letters to distinguish them from standard variables.
C Declarations, Statements, Keywords, and Literals
Declarations:
Informs the compiler about the name, type, and properties of identifiers prior to their usage.
Variable Declaration: Specifies type and identifier:
data_type variable_name;(e.g.,int age; float price; char grade;).Function Declaration (Prototype): Specifies return type, name, and parameter types:
return_type name(parameters);(e.g.,int add(int a, int b);).Type Declaration (
typedef): Creates an alias for an existing data type:typedef existing_type new_name;(e.g.,typedef int Integer; Integer score = 95;).
C Statements:
An instruction that commands the computer to perform an action.
Statements terminate with a semicolon
;, which serves as a command terminator.c int age = 20; // declaration statement age = age + 1; // assignment statement printf("%d", age); // function call statement return 0; // return statement
Keywords and Reserved Words:
Predefined identifiers reserved by C that possess fixed special meanings. They cannot be used as variable or function names.
Data Types:
int,char,float,double,voidDecision Control:
if,else,switch,case,defaultLoops:
for,while,do,continue,breakProgram Control:
return,goto,sizeofCustom Types:
struct,union,enum,typedefInvalid Example:
int return = 10;(Fails compilation becausereturnis a reserved keyword).
Literals vs. Variables:
Variable: A named memory location whose stored value can change during program execution.
Literal: A fixed, explicit value written directly in code that does not change.
Analogy: A variable acts as a storage box, whereas a literal is the concrete content placed inside the box.
Categories of Literals:
Integer: Whole numerical values (e.g.,
100,-25,0).Floating-point: Decimal or scientific notation values (e.g.,
3.14,12.5,1.23e4).Character: Single character enclosed in single quotes (e.g.,
'A',' ','%').String: Sequence of characters enclosed in double quotes (e.g., `