NIELIT Module 1

NIELIT Module 1

Programming Fundamentals

Complete Syllabus Overview

  • Fundamentals of programming
  • Program vs. algorithm, implementing algorithms
  • Language-independent algorithm representation using flowcharts and pseudo-codes
  • Functionality vs implementation, usage of right abstractions, code documentation
  • Runtime error vs logical bug, black box vs white box testing, debugging techniques

1. Algorithm

Definition: An algorithm is a clear, step-by-step sequence of instructions designed to solve a specific problem. It is written in simple, readable human language so that anyone can understand the underlying logic.

The Kitchen Analogy

Think of an algorithm as a blueprint or a recipe. If you have a recipe for baking a cake, it doesn't matter what kitchen you are in. The kitchen represents different programming languages. No matter the kitchen (language), the recipe (algorithm) remains exactly the same!

Language Independent Written in plain English or math. Not tied to C, Python, or Java.
Finite It must eventually stop. It cannot run in an infinite loop forever.
Clear & Unambiguous Each step must be perfectly clear to whoever reads it.

Example: Add Two Numbers

  1. START
  2. INPUT A
  3. INPUT B
  4. SUM = A + B
  5. DISPLAY SUM
  6. STOP

2. Pseudo-code

Definition: Pseudo-code is "fake code". It is a way to write out an algorithm so that it looks a lot like real programming code, but it is meant for humans to read, not computers.

Difference from Algorithm

Algorithms use numbered steps (Step 1, Step 2) and plain English. Pseudo-code drops the numbers, uses coding keywords (START, READ, PRINT), and uses symbols like the assignment arrow (<--).

Example: Add Two Numbers

START
  READ A
  READ B
  Sum <-- A + B
  PRINT Sum
STOP

3. Program

Definition: A program is the exact implementation of an algorithm written using a specific programming language (like C, C++, or Python) so that a computer can understand and execute it.

Example: Add Two Numbers in C main.c
#include <stdio.h> int main() { // C program to add two numbers int A = 5; int B = 10; int Sum = A + B; printf("The sum is: %d\n", Sum); return 0; }

4. 10 Examples: The Complete Flow

Problem 1. Algorithm
Numbered, Plain English
2. Pseudo-code
No Numbers, Uses <--
3. Program (in C)
Strict Code Syntax
1. Find Area of a Rectangle 1. START
2. Input L
3. Input W
4. Area = L * W
5. Print Area
6. STOP
START
  READ L
  READ W
  Area <-- L * W
  PRINT Area
STOP
int L = 5, W = 10, Area;
Area = L * W;
printf("%d", Area);
2. Check Voting Eligibility 1. START
2. Input Age
3. If Age >= 18, Print "Vote"
4. Else, Print "No Vote"
5. STOP
START
  READ Age
  IF Age >= 18 THEN
    PRINT "Vote"
  ELSE
    PRINT "No Vote"
  END IF
STOP
if (age >= 18) {
  printf("Vote");
} else {
  printf("No Vote");
}
3. Simple Interest 1. START
2. Input P, R, T
3. Int = (P * R * T) / 100
4. Print Int
5. STOP
START
  READ P, R, T
  Int <-- (P * R * T) / 100
  PRINT Int
STOP
int I = (P * R * T) / 100;
printf("%d", I);
4. Largest of Two Numbers 1. START
2. Input A, B
3. If A > B, Print A
4. Else, Print B
5. STOP
START
  READ A, B
  IF A > B THEN
    PRINT A
  ELSE
    PRINT B
  END IF
STOP
if (A > B)
  printf("%d", A);
else
  printf("%d", B);
5. Celsius to Fahrenheit 1. START
2. Input C
3. F = (C * 9/5) + 32
4. Print F
5. STOP
START
  READ C
  F <-- (C * 9/5) + 32
  PRINT F
STOP
float F = (C * 9.0/5.0) + 32;
printf("%f", F);
6. Check Even or Odd 1. START
2. Input N
3. If N % 2 == 0, Print "Even"
4. Else, Print "Odd"
5. STOP
START
  READ N
  IF N % 2 == 0 THEN
    PRINT "Even"
  ELSE
    PRINT "Odd"
  END IF
STOP
if (N % 2 == 0)
  printf("Even");
else
  printf("Odd");
7. Cube of a Number 1. START
2. Input N
3. Cube = N * N * N
4. Print Cube
5. STOP
START
  READ N
  Cube <-- N * N * N
  PRINT Cube
STOP
int cube = N * N * N;
printf("%d", cube);
8. Swap Two Numbers 1. START
2. Input A, B
3. Temp = A
4. A = B
5. B = Temp
6. Print A, B
7. STOP
START
  READ A, B
  Temp <-- A
  A <-- B
  B <-- Temp
  PRINT A, B
STOP
int temp = a;
a = b;
b = temp;
printf("%d %d", a, b);
9. Average of Three 1. START
2. Input X, Y, Z
3. Avg = (X+Y+Z)/3
4. Print Avg
5. STOP
START
  READ X, Y, Z
  Avg <-- (X+Y+Z)/3
  PRINT Avg
STOP
float avg = (x+y+z)/3.0;
printf("%f", avg);
10. Positive or Negative 1. START
2. Input Num
3. If Num > 0, Print "Pos"
4. Else, Print "Neg"
5. STOP
START
  READ Num
  IF Num > 0 THEN
    PRINT "Pos"
  ELSE
    PRINT "Neg"
  END IF
STOP
if (num > 0)
  printf("Pos");
else
  printf("Neg");