C Programming – Module 1
Flowcharts, Algorithms, Overview of
C,
Constants, Variables, Data Types &
I/O
Course Outcomes (CO1)
• At the end of Module-1, students will be able
to:
• • Explain fundamental structure of a C
program
• • Describe algorithms and flowcharts
• • Use constants, variables, and data types
• • Apply input/output functions in C
Module 1 Topics
• • Flowcharts & Algorithms
• • Overview of C (History, Importance,
Structure)
• • Programming Style
• • Compilation & Execution
• • Constants, Variables & Data Types
• • Input/Output in C
Algorithm
• • Step-by-step procedure to solve a problem
(Ch.1.6)
• • Properties: Finiteness, Definiteness,
Input/Output, Effectiveness
• Example Algorithm: Find Largest of Two
Numbers
• 1. Start
• 2. Read A, B
• 3. If A > B then Print A else Print B
Flowchart – Symbols
• • Oval – Start/Stop
• • Rectangle – Process
• • Diamond – Decision
• • Parallelogram – Input/Output
• Flowcharts provide a graphical representation
of algorithms
Flowchart Example: Add Two Numbers
Start
Read A, B
Sum = A + B
Print Sum
Stop
History of C
• • Developed by Dennis Ritchie at Bell Labs in
1972 (Ch.2.1)
• • Derived from B and BCPL
• • Used for UNIX OS development
• • Portable, efficient, widely used in compilers,
OS, embedded systems
Importance of C
• • Middle-level language (machine + human
level)
• • Portability: runs on different machines
• • Efficiency: close to hardware
• • Foundation for modern languages (C++,
Java, etc.)
Basic Structure of a C Program
• #include <stdio.h>
• int main() {
• printf("Hello, World!\n");
• return 0;
• }
• Components:
• • Documentation Section
• • Link Section
Programming Style (Ch.2.8)
• • Use meaningful variable names
• • Proper indentation and spacing
• • Commenting using // or /* */
• • Consistent formatting improves readability
Compilation and Execution (Ch.2.9)
• Steps:
• 1. Write Source Code (.c)
• 2. Compile → Object Code
• 3. Link → Executable
• 4. Execute → Output
• Using GCC:
• gcc program.c -o program
• ./program
Character Set & Tokens (Ch.3.2,
3.3)
• • Character Set: Letters, digits, special symbols
• • Tokens: Keywords, Identifiers, Constants,
Operators, Separators
• Example: int age = 25;
Keywords and Identifiers
• • Keywords: reserved words (int, float, if,
return)
• • Identifiers: user-defined names (rules:
letters, digits, _, not keyword)
• Example: int totalMarks;
Constants (Ch.3.6)
• • Integer: 10, -25
• • Floating: 3.14, -0.98
• • Character: 'A', '9'
• • String: "Hello"
• • Symbolic constants: #define PI 3.14159
Variables (Ch.3.7)
• • Named memory locations
• • Declaration: int a; float b;
• • Initialization: int a = 10;
• Rules for naming:
• • Begin with letter/underscore
• • No spaces, special characters
• • Case-sensitive
Const and Volatile (Ch.3.10, 3.11)
• • const: variable value cannot be changed
• Example: const int x = 10;
• • volatile: value may change unexpectedly
(hardware registers)
• Example: volatile int flag;
Data Types (Ch.3.9)
• • Primary: int, float, char, double
• • Derived: arrays, functions, pointers
• • User-defined: structures, unions, enum
• Example: int rollno; float marks; char grade;
Input and Output (Ch.5.1–5.5)
• • Input: scanf()
• Example: scanf("%d", &a);
• • Output: printf()
• Example: printf("Sum = %d", sum);
• Format Specifiers:
• %d (int), %f (float), %c (char), %s (string)
Common I/O Errors
• • Forgetting & in scanf()
• • Using wrong format specifier
• • Printing uninitialized variables
• Example Error: scanf("%d", a); // missing &
Module Summary
• • Algorithms & Flowcharts – stepwise +
graphical problem solving
• • C Language – history, importance, structure
• • Constants, Variables, Data Types –
foundation of programming
• • Input/Output – scanf/printf for interaction
• • Compilation process – code to executable
Practice Questions
• 1. Write an algorithm and flowchart to find
the largest of 3 numbers.
• 2. Explain the importance of C with examples.
• 3. List and explain C tokens with examples.
• 4. Write a C program to convert Celsius to
Fahrenheit.
• 5. Write a C program to calculate Simple
Interest.