Alprog - Elektro KKI
This course introduces the fundamental concepts of algorithms and programming using the C language. Students will learn how to analyze problems, design step-by-step solutions, and implement them in C. The course covers essential programming topics such as variables, data types, operators, control structures (selection and iteration), functions, arrays, pointers, and file handling.
Through lectures, hands-on coding exercises, and projects, students will develop problem-solving skills and a solid foundation in structured programming. By the end of the course, students are expected to be able to write efficient C programs, apply algorithmic thinking to solve computational problems, and understand the importance of programming discipline as a basis for more highly related engineering courses.
Module 1 : Introduction to C
Learning Objectives Understand the fundamental differences between Python and C programming lang...
1. Introduction: From Python to C
1.1 Key Differences Overview Aspect Python C Compilation Interpreted Compiled Type Syste...
2. Input/Output Operations
2.1 Output Operations 2.1.1 Basic Output - printf() Function Signature: int printf(const char *fo...
3. Variables and Data Types
3.1 Variable Declaration Python vs C: Python C x = 5 int x = 5; name = "John" char name[...
4. Arithmetic Operators
4.1 Basic Arithmetic Operators Operator Operation Python Example C Example + Addition a + ...
5. Flow Control
5.1 Conditional Statements 5.1.1 if Statement Python vs C Syntax: Python: if condition: state...
6. More Migration Guide: From Python to C
6.1 Common Syntax Differences Feature Python C Comments # This is a comment // This is a c...
7. Best Basic Practices and Style Guidelines
7.1 Naming Conventions Variables: Use descriptive names (student_count, not sc) Constants: Use u...
8. Practical Examples
8.1 Complete Program Examples Example 1: Simple Calculator #include <stdio.h> int main() { f...
9. Common Debugging Tips
9.1 Compilation Errors Missing semicolons: Add ; at the end of statements Undeclared variables: ...
Module 2 : Functions in C
Learning Objectives: Understand the concept and importance of functions in C programmingDeclare ...
1. Introduction to Functions
1.1 What are Functions? Functions are self-contained blocks of code that perform specific tasks. ...
2. Function Declaration, Definition, and Calling
2.1 Function Anatomy A C function consists of several parts: return_type function_name(parameter_...
3. Parameters and Arguments
3.1 Terminology Parameters (Formal Parameters): Variables in the function definition Arguments (...
4. Return Statement
4.1 Basic Return Usage The return statement serves two purposes: Return control to the calling f...
5. Variable Scope and Lifetime
5.1 Local Variables Variables declared inside a function are local to that function: Scope: Only...
6. Bonus: Some C Library Functions
Throughout this module, we've focused on defining our own functions. However, C also provides a r...
7. Recursion
7.1 Understanding Recursion Recursion is a programming technique where a function calls itself. E...
8. Function Examples and Applications
8.1 Menu-Driven Program #include <stdio.h> // Function prototypes void display_menu(void); int g...
9. Common Errors and Debugging
9.1 Function Declaration Errors Error 1: Missing Function Prototype // ERROR: Function used befor...
Module 3 : Array (Static)
By the end of this module, students will be able to: - Understand the fundamental differences be...
1. Introduction: From Python Lists to C Arrays
1.1 Key Differences Overview Aspect Python Lists C Arrays Size Dynamic (can grow/shrink) F...
2. Array Declaration and Initialization
2.1 Basic Array Declaration Python vs C Comparison: Python C numbers = [1, 2, 3, 4, 5] int...
3. Array Indexing and Access
3.1 Basic Indexing Python vs C Indexing: Operation Python C First element list[0] array[0]...
4. Array Input and Output Operations
4.1 Reading Array Elements 4.1.1 Reading with Known Size #include <stdio.h> int main() { int...
5. Common Array Operations
5.1 Array Traversal 5.1.1 Forward Traversal // Python equivalent: for item in list: for (int i = ...
6. Mathematical Operations on Arrays
6.1 Statistical Operations 6.1.1 Sum and Average #include <stdio.h> int sum_array(int arr[], int...
7. Character Arrays and Strings
7.1 Character Arrays vs Strings Understanding C Strings: In C, strings are arrays of characters t...
8. Multi-dimensional Arrays
8.1 Two-Dimensional Arrays 8.1.1 Declaration and Initialization // Declaration int matrix[3][4]; ...
Module 4 : Pointers & Dynamic Array
By the end of this module, students will be able to: Understand the concept and purpose of point...
1. Introduction to Pointers
1.1 What are Pointers? A pointer is a variable that stores the memory address of another variable...
2. Pointer Basics
2.1 Declaring Pointers Syntax: data_type *pointer_name; Examples: int *ptr; // Pointer to...
3. Pointer Arithmetics
3. Pointer Arithmetic Pointers can be incremented, decremented, and compared. When you perform ar...
4. Pointers and Arrays
Arrays and pointers have a very close relationship in C. In many contexts, an array name acts as ...
5. Pointers and Functions
Pointers are essential for functions to modify variables from the calling code and to work effici...
6. Pointers and Strings
In C, strings are arrays of characters, so pointers work naturally with strings. 6.1 String Repre...
7. Dynamic Memory Allocation & Array
7.1 Introduction to Dynamic Memory Up until now, we've used static memory allocation where array ...
8. Common Pointer Pitfalls and Best Practices
8.1 Uninitialized Pointers WRONG: int *ptr; // Uninitialized - contains garbage address *ptr...
9. Practical Examples with Dynamic Memory
9.1 Dynamic Array with User Input #include <stdio.h> #include <stdlib.h> int main() { int n,...
Module 5 : Data Types (Struct, Enum, TypeDef) & File I/O
By the end of this module, students will be able to: - Understand and implement user-defined dat...
1. Introduction to User-Defined Data Types
1.1 Why User-Defined Types? In previous modules, we learned about basic data types like int, floa...
2. Structures (struct)
2.1 What is a Structure? A structure is a user-defined data type that groups variables of differe...
3. Enumerations (enum)
3.1 What is an Enumeration? An enumeration is a user-defined data type consisting of a set of nam...
4. Type Definitions (typedef)
4.1 What is typedef? typedef creates aliases (alternative names) for existing data types. It make...
5. File Input/Output
5.1 Why File I/O? So far, all our programs lose their data when they terminate. File I/O allows p...
Module 6 : Linked List
By the end of this module, students will be able to: - Understand the concept and structure of l...
1. Introduction to Linked Lists
1.1 What is a Linked List? A linked list is a linear data structure where elements are not stored...
2. Node Structure
2.1 Defining a Node In C, a node is typically defined using a structure: // Definition of a node ...
3. Singly Linked List Operations
3.1 Creating an Empty List #include <stdio.h> #include <stdlib.h> struct Node { int data; ...
4. Complete Singly Linked List Example
#include <stdio.h> #include <stdlib.h> // Node structure struct Node { int data; struct ...
5. Doubly Linked List
5.1 Node Structure struct DNode { int data; struct DNode *prev; // Pointer to previous n...
6. Circular Linked List
6.1 Structure In a circular linked list, the last node points back to the first node (or head). s...
7. Advanced Linked List Operations
7.1 Reverse a Singly Linked List Method 1: Iterative void reverseList(struct Node **head) { s...
8. Practical Applications
8.1 Polynomial Addition #include <stdio.h> #include <stdlib.h> // Node for polynomial term struc...
9. Common Errors and Debugging
9.1 Memory Leaks Problem: void createList() { struct Node *head = (struct Node*)malloc(sizeof...
Module 7: Searching & Sorting
By the end of this module, students will be able to: Understand fundamental searching algorithms...
1. Introduction to Searching
1.1 What is Searching? Searching is the process of finding a particular element or checking if an...
2. Linear Search
2.1 Concept Linear Search (also called Sequential Search) checks every element in the array seque...
3. Binary Search
3.1 Concept Binary Search is a fast search algorithm that works on sorted arrays by repeatedly di...
4. Introduction to Sorting
4.1 What is Sorting? Sorting is the process of arranging elements in a specific order (ascending ...
5. Simple Sorting Algorithms
5.1 Bubble Sort Concept Bubble Sort repeatedly steps through the list, compares adjacent elements...
6. Efficient Sorting Algorithms
6.1 Merge Sort Concept Merge Sort is a divide-and-conquer algorithm that divides the array into h...
7. Comparison of Sorting Algorithms
7.1 Performance Summary // Test all sorting algorithms #include <time.h> void testSortingAlgorit...
8. Practical Applications
8.1 Search and Sort Combined #include <stdio.h> #include <stdlib.h> #include <string.h> // Stude...
Module 8 : OOP (SOLID, Encapsulation, Abstraction)
By the end of this module, students will be able to: - Understand the fundamental concepts of Ob...
1. Introduction: From Procedural to Object-Oriented Programming
1.1 What is Object-Oriented Programming? Object-Oriented Programming (OOP) is a programming parad...
2. C++ Basics: Essential Differences from C
2.1 Basic Syntax Differences C vs C++ Comparison: Feature C C++ File Extension .c .cpp I...
3. Classes and Objects
3.1 Understanding Classes and Objects Definition: Class: A blueprint or template for creating ob...
4. Encapsulation
4.1 What is Encapsulation? Encapsulation is the bundling of data (attributes) and methods that op...
5. Abstraction
5.1 What is Abstraction? Abstraction is the concept of hiding complex implementation details and ...
6. SOLID Principles
6.1 Introduction to SOLID SOLID is an acronym for five design principles that make software desig...
7. Constructors and Destructors
7.1 Constructors Purpose: Special member function that initializes an object when it's created. T...
Modul 9: OOP - Inheritance
After completing this module, students are expected to: - Understand the concept of inheritance ...
1. Basic Concepts of Inheritance
1.1 What is Inheritance? Inheritance is a mechanism where a class (derived/child class) can inher...
2. Types of Inheritance and Method Overriding
2.1 Single Inheritance Definition: One derived class inherits from one base class. #include <iost...
3. Practical Applications and Best Practices
3.1 Complete Example: University Management System #include <iostream> #include <vector> #include...