Unit II: Introduction to Computing
1. Art of Programming through Algorithms
An Algorithm is a step-by-step procedure or a set of rules to be followed in calculations or other problem-solving operations. Before writing actual code, programmers use algorithms to define the logic of the program.
Qualities of a Good Algorithm:
- Finiteness: It must terminate after a finite number of steps.
- Definiteness: Each step must be clearly defined and unambiguous.
- Input: It should have zero or more well-defined inputs.
- Output: It must produce at least one output.
- Effectiveness: Steps must be basic enough to be carried out exactly.
2. Flowcharts: Symbols and Rules
A Flowchart is a pictorial or graphical representation of an algorithm. It uses various symbols to represent different types of operations.
Flowchart Symbols:
Rules for Designing Flowcharts:
- Flow should usually be from top to bottom or left to right.
- Only one flow line should come out of a process symbol.
- Only one flow line should enter a decision symbol, but two or three may leave it.
- Avoid intersection of flow lines for better clarity.
3. Overview of C: History and Importance
C is a powerful general-purpose programming language developed by Dennis Ritchie at Bell Laboratories in the early 1970s.
- History: It was originally developed to write the UNIX operating system.
- Importance: C is known for its efficiency and portability. It provides low-level access to memory while remaining easy to read for humans. Most modern languages like C++, Java, and Python have roots in C.
4. Basic Structure and Execution of C
A C program follows a specific template to ensure the compiler can process it correctly.
Basic Structure of a C Program:
- Documentation Section: Comments about the program.
- Link Section: Header file inclusions (e.g.,
#include <stdio.h>).
- Definition Section: Defining symbolic constants.
- Global Declaration Section: Declaring variables used throughout the program.
- Main Function: The entry point where execution begins (
main() { ... }).
- Subprogram Section: User-defined functions.
Executing a C Program:
The execution involves four main steps:
- Creating the Program: Writing code in an editor and saving it as
.c.
- Compiling: The compiler checks for syntax errors and converts code to an object file.
- Linking: Linking the object file with library functions to create an executable (
.exe).
- Running: Executing the program to see the output.
Exam Tips
- Flowchart Accuracy: Always use a diamond for "if" conditions and a parallelogram for "print" or "input" statements.
- Algorithm vs. Flowchart: Algorithms are text-based; Flowcharts are image-based. Both describe the same logic.
- C History: Mentioning Dennis Ritchie and UNIX in history questions usually earns extra points.
Frequently Asked Questions
Q1: Why is C called a "middle-level" language?
Because it combines features of high-level languages (human readability) with the power and efficiency of low-level languages (memory manipulation).
Q2: Can a flowchart have multiple start points?
No, a flowchart must have exactly one START terminal to represent the beginning of execution.