0% found this document useful (0 votes)
0 views16 pages

PPS Unit-1 Notes

This document introduces the fundamentals of computer programming, detailing the basic operations of a computer, including input, storage, processing, output, and control. It explains the components of the Central Processing Unit (CPU), types of memory (RAM and ROM), and the elements of a computer system such as hardware, software, and data. Additionally, it outlines the problem-solving process in programming, emphasizing the importance of understanding and analyzing problems before developing solutions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views16 pages

PPS Unit-1 Notes

This document introduces the fundamentals of computer programming, detailing the basic operations of a computer, including input, storage, processing, output, and control. It explains the components of the Central Processing Unit (CPU), types of memory (RAM and ROM), and the elements of a computer system such as hardware, software, and data. Additionally, it outlines the problem-solving process in programming, emphasizing the importance of understanding and analyzing problems before developing solutions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT-1 Introduction to Programming

PPS-PROGRAMMING FOR PROBLEM SOLVING

UNIT-1

1 INTRODUCTION TO COMPUTERS

A computer is a very powerful and versatile machine capable of performing a multitude of


different tasks, yet it has no intelligence or thinking power. The intelligence Quotient (I.Q) of
a computer is zero. A computer performs many tasks exactly in the same manner as it is told
to do. In order to instruct a computer correctly, the user must have clear understanding of the
problem to be solved. Once the problem is well-defined and a method of solving it is developed,
then instructing the computer to solve the problem becomes relatively easier task. Thus, before
attempt to write a computer program to solve a given problem. It is necessary to formulate or
define the problem in a precise manner. Once the problem is defined, the steps required to solve
it, must be stated clearly in the required order.
BASIC COMPUTER ORGANIZATION

A computer performs basically five major operations or functions irrespective of their size and
make. These are 1) it accepts data or instructions by way of input, 2) it stores data, 3) it can
process data as required by the user, 4) it gives results in the form of output, and 5) it controls
all operations inside a computer.
1. Input: This is the process of entering data and programs in to the computer system. You
should know that computer is an electronic machine like any other machine which takes as
inputs raw data and performs some processing giving out processed data. Therefore, the input
unit takes data from us to the computer in an organized manner for processing.
UNIT-1 Introduction to Programming

2. Storage: The process of saving data and instructions permanently is known as storage. Data
has to be fed into the system before the actual processing starts. It is because the processing
speed of Central Processing Unit (CPU) is so fast that the data has to be provided to CPU with
the same speed. Therefore the data is first stored in the storage unit for faster access and
processing. This storage unit or the primary storage of the computer system is designed to do
the above functionality. It provides space for storing data and instructions.
The storage unit performs the following major functions:
❖ All data and instructions are stored here before and after processing.
❖ Intermediate results of processing are also stored here.
3. Processing: The task of performing operations like arithmetic and logical operations is
called processing. The Central Processing Unit (CPU) takes data and instructions from the
storage unit and makes all sorts of calculations based on the instructions given and the type of
data provided. It is then sent back to the storage unit.

4. Output: This is the process of producing results from the data for getting useful information.
Similarly the output produced by the computer after processing must also be kept somewhere
inside the computer before being given to you in human readable form. Again the output is also
stored inside the computer for further processing.
5. Control: The manner how instructions are executed and the above operations are performed.
Controlling of all operations like input, processing and output are performed by control unit. It
takes care of step by step processing of all operations inside the computer.

INPUT UNIT

The input unit is formed by the input devices attached to the computer. Input devices are used
to interact with a computer system or used enter data and instructions to the computer. These
devices convert input data and instructions into a suitable binary form such as ASCII, which
can be acceptable by the computer. In brief, an input unit performs the following function:

• It accepts data and instruction from the outside worlds.


• It converts these data and instruction into computer understandable from a binary form.
• It supplied the converted data and instruction to the computer system for further
processing.

E.g of input devices are keyboard, mouse, scanner etc.


UNIT-1 Introduction to Programming

OUTPUT UNIT

The output unit is formed by the output devices attached to the computer. Output devices are
used to present result produced by the computer to the users. The output from the computer is
in the form electric signals, which is then converted into human understandable form into
human readable form. The examples of output devices are the monitor, printer and speaker.

The main functions of the output unit are as follow:

• Accepts the result produced by the computer which is in electric binary signals.
• It then converts the result into human readable form.
• Finally, it supplied the converted results to the outside word.

CENTRAL PROCESSING UNIT (CPU)

The CPU has three components responsible for different function, these components are
Control units, arithmetic-logical unit (ALU) and Register. The ALU and the CU of a computer
system are jointly known as the central processing unit. CPU is the brain of any computer
system. It is just like brain that takes all major decisions, makes all sorts of calculations and
directs different parts of the computer functions by activating and controlling the operations.

ARITHMETIC LOGICAL UNIT (ALU)

After you enter data through the input device it is stored in the primary storage unit. The actual
processing of the data and instruction are performed by Arithmetic Logical Unit. The major
operations performed by the ALU are addition, subtraction, multiplication, division, logic and
comparison. Data is transferred to ALU from storage unit when required. After processing the
output is returned back to storage unit for further processing or getting stored. The main
functions of ALU are as follow:

• It accepts operands from registers.


• It performs arithmetic and logic operations.
• It returns a result to register or a memory.

CONTROL UNIT (CU)

The next component of computer is the Control Unit, which acts like the supervisor seeing that
things are done in proper fashion. The control unit determines the sequence in which computer
programs and instructions are executed. Things like processing of programs stored in the main
memory, interpretation of the instructions and issuing of signals for other units of the computer
to execute them. It also acts as a switch board operator when several users access the computer
simultaneously. Thereby it coordinates the activities of computer’s peripheral equipment as
they perform the input and output. Therefore it is the manager of all operations mentioned in
the previous section.. The main functions of control units are given below:

• It performs the data processing operations with the aid of program prepared by the user
and send control signals to various parts of the computer system.
UNIT-1 Introduction to Programming

• It gives commands to transfer data from the input devices to the memory to an
arithmetic logic unit.
• It also transfers the results from ALU to the memory and then to the output devices.
• It stores a program in the memory.
• It fetches the required instruction from the main storage and decode each instruction
and hence execute them in sequence.

MEMORY UNIT

This unit is also called storage unit. The data and instructions, which are entered through an
input unit must be stored on the computer before the actual processing starts. The result
produces by the computer after processing is also kept somewhere before passed to the output
units. If intermediate results are produced during processing, it should be stored in somewhere
in memory. The storage unit of a computer performs all these needs. In brief, the specific
functions performed by the storage unit are as follow:

• It stored data and instructions, which are entered through input devices.
• It stores an intermediate result of processing.
• It stores the final result of processing before these results are passed to an output device.

The storage unit of computers consists of two types of memory which are RAM and ROM.
There are two key types of primary memory, RAM, or random access memory and ROM, or
read-only memory

1) RAM ComputerMemory

The acronym RAM stems from the fact that data stored in random access memory can be
accessed – as the name suggests – in any random order. Or, put another way, any random
bit of data can be accessed just as quickly as any other bit.

Data that is required for imminent processing is moved to RAM where it can be accessed
and modified very quickly, so that the CPU is not kept waiting. When the data is no longer
required it is shunted out to slower but cheaper secondary memory, and the RAM space
that has been freed up is filled with the next chunk of data that is about to be used.

Types of RAM

DRAM: DRAM stands for Dynamic RAM, and it is the most common type of RAM used
in computers. The oldest type is known as single data rate (SDR) DRAM, but newer
computers use faster dual data rate (DDR) DRAM. DDR comes in several versions
including DDR2 , DDR3, and DDR4, which offer better performance and are more energy
efficient than DDR. However different versions are incompatible, so it is not possible to mix
DDR2 with DDR3 DRAM in a computer system. DRAM consists of a transistor and a
capacitor in eachcell.

SRAM: SRAM stands for Static RAM, and it is a particular type of RAM which is faster
than DRAM, but more expensive and bulker, having six transistors in each cell. For those
reasons SRAM is generally only used as a data cache within a CPU itself or as RAM in
UNIT-1 Introduction to Programming

very high-end server systems. A small SRAM cache of the most imminently-needed data
can result in significant speed improvements in a system

The key differences between DRAM and SRAM is that SRAM is faster than DRAM -
perhaps two to three times faster - but more expensive and bulkier. SRAM is usually
available in megabytes, while DRAM is purchased in gigabytes.

DRAM uses more energy than SRAM because it constantly needs to be refreshed to
maintain data integrity, while SRAM - though volatile – does not need constant refreshing
when it is powered up.

2) ROM ComputerMemory

ROM stands for read-only memory, and the name stems from the fact that while data can
be read from this type of computer memory, data cannot normally be written to it. It is a
very fast type of computer memory which is usually installed close to the CPU on the
motherboard.

ROM is a type of non-volatile memory, which means that the data stored in ROM persists
in the memory even when it receives no power – for example when the computer is turned
off. In that sense it is similar to secondary memory, which is used for long termstorage.

ROM is also used in simpler electronic devices to store firmware which runs as soon as the
device is switched on.

Types of ROM
ROM is available in several different types, including PROM, EPROM, and EEPROM.

PROM PROM stands for Programmable Read-Only Memory, and it is different from true
ROM in that while a ROM is programmed (i.e. has data written to it) during the
manufacturing process, a PROM is manufactured in an empty state and then programmed
later using a PROM programmer orburner.

EPROM EPROM stands for Erasable Programmable Read-Only Memory, and as the name
suggests, data stored in an EPROM can be erased and the EPROM reprogrammed. Erasing
an EPROM involves removing it from the computer and exposing it to ultraviolet light
before re- burning it.

EEPROM EEPROM stands for Electrically Erasable Programmable Read-Only Memory,


and the distinction between EPROM and EEPROM is that the latter can be erased and
written to by the computer system it is installed in. In that sense EEPROM is not strictly
read-only. However in many cases the write process is slow, so it is normally only done to
update program code such as firmware or BIOS code on an occasionalbasis

I. PRIMARY STORAGE
UNIT-1 Introduction to Programming

Memory storage that communicates directly with CPU is called main memory. It enables the
computer to store, at least temporarily data and instruction. It is mainly used to hold data and
instructions and as well as the intermediate result of processing which the computer system is
currently working on. Primary memory is volatile, that is, it loses its content when power
supply is off. The ROM is nonvolatile as the content is available even if power is on or off.

II. SECONDARY STORAGE

Auxiliary storage is also known as secondary storage. It is the memory that supplements the
main memory. These are a non-volatile memory. It is mainly used to transfer data to program
from one computer to another computer. There is high capacity storage devices used to store
data and program permanently. These are also used as backup devices which allow to store the
valuable information as backup on which you are working on. The examples of secondary
memory are Magnetic Disk, Optical disk, etc.

III. REGISTERS

Registers are the high-speed temporary storage locations in the CPU made from electronic
devices such as transistors, flip-flops, etc. So, registers can be thought as CPU’s working
memory. Register are primarily used to store data temporarily during the execution of a
program and are accessible to the user through instructions. These are the part of Control unit
and ALU rather than of memory. Hence, their contents can be handled much faster than the
contents of memory. The number of registers varies from computer to computer. There are
some registers which are common to all computers. Five registers that are essential for
instruction execution are:

• Program Counter (PC): Contains the address of the next instruction to be fetched.
• Instruction Register (IR): Contains the instruction most recently fetched.
• Memory Address registers (MAR): Contain the address of a location in memory for
read and write operation.
• Memory Buffer Register (MBR): It contains the value to be stored in memory or the
last value read from memory.
• Accumulator (ACC): An accumulator is a general purpose register used for storing
temporary result and result produced by the arithmetic logic unit.

THE ELEMENTS OF COMPUTER SYSTEM

• HARDWARE
• SOFTWARE
• DATA OR INFORMATION
• PROCEDURE (DATA WHICH THE COMPUTER CONVERTS)
• USER
• COMMUNICATION

1. HARDWARE : Hardware refers to the part of the computer which we can touch. It is the
physical devices of the computer. It consists of interconnected electronic equipment
that controls everything the computer does. It includes input devices, input devices,
output devices, processing devices and storage devices. Example of hardware are
keyboard, monitor, CPU, hard disk and RAM.
UNIT-1 Introduction to Programming

2. SOFTWARE : The software is the term used to describe the instruction that tells the
hardware, what and how to perform a task. Without software, the hardware is useless.
Examples of software are Window 7, MS office, Internet explorer, etc.

3. DATA/INFORMATION: The function of a computer system is to convert data into


information. Data can be considered as the raw facts whether in a paper, electronic or
the other form that is processed by the computer. In other words , data consist of the
raw facts and figures that are processed to form information. Information is summarized
data or manipulated or processed data.

4. PEOPLE : People constitute the most important parts of the computer system. People
operate the computer hardware and create the computer software. They also follow a
certain procedure when using the hardware and software.

5. PROCEDURE : The procedure is a description of how things are done, step for
accomplishing a result. Procedure for a computer system appears in documentation
manual, also known as reference manual which contains instruction, rules, and
guidelines to follow when using hardware and software. When you buy a
microcomputer or software package, it comes with one or more documentation
manuals.

6. COMMUNICATION : When one computer system is set up to share data and information
electronically with another computer system, communication becomes a system
element. In other words, the manner on which the various individual system are
connected by wires, cables, phone lines, microwave, Wi-Fi or satellite is an element of
the total computer system.

PROBLEM SOLVING
In order to solve a problem by the computer, one has to pass though certain stages or steps.
They are
1. Understanding the problem
2. Analyzing the problem
3. Developing the solution
4. Coding and implementation.

1. UNDERSTANDING THE PROBLEM: Here we try to understand the problem to be solved in


totally. Before with the next stage or step, we should be absolutely sure about the
objectives of the given problem.
2. ANALYZING THE PROBLEM: After understanding thoroughly the problem to be solved, we
look different ways of solving the problem and evaluate each of these methods. The
idea here is to search an appropriate solution to the problem under consideration. The
end result of this stage is a broad overview of the sequence of operations that are to be
carries out to solve the given problem.
3. DEVELOPING THE SOLUTION: Here the overview of the sequence of operations that was
the result of analysis stage is expanded to form a detailed step by step solution to the
problem under consideration.
4. CODING AND IMPLEMENTATION: The last stage of the problem solving is the conversion
of the detailed sequence of operations in to a language that the computer can
understand. Here each step is converted to its equivalent instruction or instructions in
the computer language that has been chosen for the implantation.
UNIT-1 Introduction to Programming

Problem solving is explained by three different approaches. They are by algorithm,


pseudo code and flowchart.

ALGORITHM

DEFINITION
A set of sequential steps usually written in Ordinary Language to solve agiven problem is called
Algorithm.

STEPS :
An algorithm can be defined as“a complete, unambiguous, finite numberof logical steps for
solving a specific problem “
1. IDENTIFICATION OF INPUT : For an algorithm, there are quantities tobe supplied called
input and these are fed externally. The input is to be indentifiedfirst for any specified
problem.
2. IDENTIFICATION OF OUTPUT: From an algorithm, at least one quantityis produced, called
for any specified problem.
3. IDENTIFICATION THE PROCESSING OPERATIONS: All the calculationsto be performed in
order to lead to output from the input are to be identified inan orderly manner.
4. PROCESSING DEFINITENESS: The instructions composing thealgorithm must be clear and
there should not be any ambiguity in them.
5. PROCESSING FINITENESS: If we go through the algorithm, then forall cases, the algorithm
should terminate after a finite number of steps.
6. POSSESSING EFFECTIVENESS : The instructions in the algorithm must be sufficiently basic
and in practice they can be carries out easily.

PROPERTIES OF ALGORITHM:
1. FINITENESS : An algorithm must terminate in a finite number of steps
2. DEFINITENESS : Each step of the algorithm must be precisely andunambiguously stated
3. EFFECTIVENESS : Each step must be effective, in the sense that it shouldbe primitive
easily convert able into program statement) can be performed exactlyin a finite amount
of time.
4. GENERALITY : The algorithm must be complete in itself so that it can be used to solve
problems of a specific type for any input data.
5. INPUT/OUTPUT : Each algorithm must take zero, one or more quantities asinput data
produce one or more output values.

EXAMPLE
Suppose we want to find the average of three numbers, the algorithm isas follows:
Step 1: Read the numbers a, b, c
Step 2: Compute the sum of a, b and c
Step 3: Divide the sum by 3
Step 4; Store the result in variable d
Step 5: Print the value of d
Step 6: End of the program

Swapping two Numbers


UNIT-1 Introduction to Programming

Algorithm:

1. Start the program

2. Read two numbers a and b

3. Declare a third temporary variable c

4. Copy value of a and store in c

5. Copy value of a and store in b

6. Copy value of c and store in a

7. Print the values of a and b

8. Stop the program

Find number is prime or not:


Algorithm:
1. Start the program
2. Read the value of number n
3. Initialize I to 2
4. Divide n by I
5. Check the remainder equals to 0 or not
6. If Step 5 is No print n is not a prime number else increment the value of I by 1
7. Repeat step 4 to 6 till n/2 times
8. If the number is not divisible by any other number from 2 to n/2 numbers print the
number is Prime number
9. End the program

Algorithm to test whether a given integer value is prime or not.


Step 1: M 2
Step 2: read N
Step 3: MAX SQRT (N)
Step 4: While M < = MAX do
4.1 if (M* (N/M) = N
4.1.1 then
[Link] go to step 7
4.2. M M + 1
Step 5: Write “number is prime”
Step 6: go to step 8
Step 7: Write “number is not a prime”
Step 8: end.

FLOWCHART :
A flow chart is a step by step diagrammatic representation of the logicpaths to solve a given
problem. It is a visual or graphical representation of an [Link] flowcharts are pictorial
UNIT-1 Introduction to Programming

representation of the methods to b used to solve a given problem and help a great deal to analyze
the problem and plan its solution in a systematic and orderly manner. A flowchart when
translated in to a proper computer language, results in a complete program.
ADVANTAGES OF FLOWCHARTS
[Link] flowchart shows the logic of a problem displayed in pictorial fashion which felicitates
easier checking of an algorithm
2. The Flowchart is good means of communication to other users. It is also a compact means
of recording an algorithm solution to a problem.
3. The flowchart allows the problem solver to break the problem into parts. These parts can be
connected to make master chart
4. The flowchart is a permanent record of the solution which can be consulted at a later time.
DIFFERENCES BETWEEN ALGORITHM AND FLOWCHART

Algorithm Flowchart

1. A method of representing the 1. Flow chart is diagrammatic


step-by-step logical procedure for representation of an algorithm. It is
solving a problem constructed using different types of boxes
and symbols.
2. It contains step-by-step English 2. The flowchart employs a series of blocks
descriptions, each step representing and arrows, each of which represents a
a particular operation leading to particular step in an algorithm
solution of problem

3. These are particularly useful for 3. The e are useful for detailed
small problems representations of complicated programs

4. For complex programs, 4. For complex programs, Flowcharts


algorithms prove to be Inadequate prove to be adequate

SYMBOLS USED IN FLOWCHART

Different symbols are used for different states in flowchart, For example: Input/Output and
decision making has different symbols. The table below describes all the symbols that are used
in making flowchart

Symbol Purpose Description

Flow line Used to indicate the flow of logic by connecting symbols.

Terminal(Stop/Start) Used to represent start and end of flowchart.


UNIT-1 Introduction to Programming

Symbol Purpose Description

Input/output Used for input and output operation.

Processing Used for arithmetic operations and data-manipulations.

Used to represent the operation in which there are two


Decision
alternatives, true and false.

On-page Connector Used to join different flow line

Off-page Connector Used to connect flowchart portion on different page.

Predefined Used to represent a group of statements performing one


Process/Function processing task.

Draw a flowchart to add two numbers entered by user.


UNIT-1 Introduction to Programming
UNIT-1 Introduction to Programming

Draw flowchart to find the largest among three different numbers entered by user.
UNIT-1 Introduction to Programming

Draw a flowchart to find all the roots of a quadratic equation ax2+bx+c=0


UNIT-1 Introduction to Programming

Draw a flowchart to find the Fibonacci series till term≤1000.

Though, flowchart is useful in efficient coding, debugging and analysis of a program, drawing
flowchart in very complicated in case of complex programs and often ignored.
UNIT-1 Introduction to Programming

PSEUDOCODE
The Pseudo code is neither an algorithm nor a program. It is an abstract form of a program. It
consists of English like statements which perform the specific operations. It is defined for an
algorithm. It does not use any graphical representation. In pseudo code, the program is
represented in terms of words and phrases, but the syntax of program is not strictly followed.

ADVANTAGES:
* Easy to read
* Easy to understand
* Easy to modify.

EXAMPLE :
Write a pseudo code to perform the basic arithmetic operations.
Read n1, n2
Sum = n1 + n2
Diff = n1 – n2
Mult = n1 * n2
Quot = n1/n2
Print sum, diff, mult, quot
End

You might also like