Chapter 1: Introduction to Computing

📌 Learning Objectives
  • LO 1.1: Know the structure of a computer and have an idea about its functioning
  • LO 1.2: Learn to develop programming logic through algorithms and flowcharts

1.1 Components of a Computer

A computer is an electronic device used to perform computations involving arithmetic and logical operations. The major components are the CPU, input devices, output devices, and memory.

+-----------+     +-----------------+     +------------+
|   Input   |---->|                 |---->|  Output    |
|  Devices  |     |       CPU       |     |  Devices   |
+-----------+     |                 |     +------------+
                  +-----------------+
                          ^
                          |
                          v
                  +-----------------+
                  |     Memory      |
                  +-----------------+

Fig. 1.1: Basic components of a computer

Central Processing Unit (CPU)

The CPU is the unit where all processing takes place. It consists of:

Memory

Memory is classified into:

1.2 Algorithms and Flowcharts

An algorithm is a finite set of unambiguous instructions that, when executed, performs a task correctly. It has three characteristics:

Example 1: Algorithm to Find Average of Three Numbers

📝 Worked-Out Problem 1.1

Algorithm AVERAGE:

Step 0: START
Step 1: INPUT first number into variable A
Step 2: INPUT second number into variable B
Step 3: INPUT third number into variable C
Step 4: COMPUTE SUM = A + B + C
Step 5: COMPUTE AVG = SUM / 3
Step 6: DISPLAY AVG
Step 7: END

Flowchart Symbols

SymbolNameDescription
TerminalStart/End of flowchart
Input/OutputInput or output operation
ProcessProcessing/imperative statement
DecisionConditional/decision making

Example 2: Finding Maximum of Two Numbers

📝 Worked-Out Problem 1.2

Algorithm MAXIMUM:

Step 0: START
Step 1: INPUT first number into A
Step 2: INPUT second number into B
Step 3: IF A > B THEN
           MAX = A
        ELSE
           MAX = B
        END IF
Step 4: DISPLAY MAX
Step 5: END

Flowchart:

        [START]
           |
           v
    [INPUT A, B]
           |
           v
         /   \
        /     \
       / A>B?  \
      /         \
     /           \
    (True)       (False)
      |            |
      v            v
  [MAX = A]    [MAX = B]
      |            |
      \            /
       \          /
        \        /
         v      v
       [DISPLAY MAX]
           |
           v
         [END]

1.3 Example 3: Sum of First N Natural Numbers (Iteration)

📝 Worked-Out Problem 1.3

Algorithm SUM-N:

Step 0: START
Step 1: INPUT N
Step 2: I = 1
Step 3: SUM = 0
Step 4: REPEAT Steps (a)-(b) WHILE I <= N
           (a) SUM = SUM + I
           (b) I = I + 1
        END WHILE
Step 5: DISPLAY SUM
Step 6: END

Sample Programe 1

#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b,c;
    clrscr();
    printf("Enter the two values");
    scanf("%d%d",&a,&b);
    c=a+b;
    printf("The sum is %d",c);
    getch();
}
           

Result

Enter the two values2
3 
The sum is 5

    

Write a C program to read two integer values from the user and display their sum.