PPS Chapter-1
PPS Chapter-1
Subject
Programming for Problem Solving (3110003)
Chapter – 1
Introduction to Computer and Programming
CONTENTS
1. INTRODUCTION
1.1. Advantages (Characteristics) of Computers
1.2. Limitations of Computers
2. BASIC BLOCK DIAGRAM AND FUNCTIONS OF VARIOUS COMPONENTS OF
COMPUTER
3. CONCEPT OF HARDWARE AND SOFTWARE
3.1. Types of Software
3.2. Difference between Compiler and Interpreter
4. PROGRAMMING LANGUAGES
5. FLOWCHART
5.1. Flowchart Examples
6. ALGORITHM
6.1. Algorithm Examples
1. INTRODUCTION
• A computer is an electronic device which accepts data from outside world and
manipulates or process it according to instruction given at high speed.
• It has memory to store large amount of data, can process it in accurate form with
high speed by using powerful processor.
• Computer is also called data processor because it can store, process and retrieve
data whenever required.
• A computer cannot work of its own, but work is based on some prior instructions
given to it that is known as computer programming.
• According to instruction it performs action. A computer therefore follows a series
of instructions, programmed into its memory by its user.
2. Output Unit – The output device receives results and other information from
the computer and provide them to the users.
• The computer sends information to an output device in the binary form.
• Loader - Loader loads the program into the main memory area where the
program can be executed. Example is Boot Strap loader.
• Linker – Linker links the symbolic code of source and library files to make
executable program.
• General Purpose Software – They are used for many numbers of tasks and
provide many features. Examples are MS Office, Page maker, etc.
4. PROGRAMMING LANGUAGES
• A programming language is a set of rules that tells the computer what operations
to do. These languages are used by the programmers to create other kinds of
software.
• It is classified as:
1. Machine language or low-level language
2. Assembly language
3. High-level language
• Advantages:
1. Program execution is faster in comparison with others.
2. Due to direct writing into machine code the size of code is compact and
small in comparison with other languages.
3. It occupies less memory.
• Disadvantages or Drawbacks:
1. It requires depth technical knowledge to debug program.
2. Need to remember all operation codes and memory addresses.
3. Due to only two combinations (0’s and 1’s) it is difficult to understand.
• Advantages:
o The programs are very easy to understand or debug.
o The programs are fast to enter using alphanumeric keys of keyboard.
• Disadvantages or Drawbacks:
o It requires assembler to translate assembly language program to
machine language program.
• Advantages:
o The high-level sentences are easy sentences, so it is very easy to learn.
o No need to learn computer architecture.
o The programs are very easy to understand or debug.
o The programs are fast to enter using alphanumeric keys of keyboard.
o The programs are portable.
• Disadvantages or Drawbacks:
o High-level language program requires compiler or interpreter to
translate high-level language program into machine language that
means object code.
o Object code needs loader to load code into the main memory and
execute that program.
o Programmers need to learn structure of high-level language program
and syntax of every statement.
o Some high-level languages are dependent on operating system.
5. FLOWCHART
• A flowchart is a graphical representation of a program flow of any problem to
be solved by computer programming language.
• It is prepared first before writing any program.
• It is used to correct and debug a program flow after coding part is completed.
• Through flowchart it is easy to understand logic and sequence of problem.
2. Input / Output:
4. Decision:
6. Connector:
7. Loop:
• Advantages:
o Easy to draw.
o Easy to understand logic.
o Easy to identify mistakes by non-computer person.
o Easy to show branching and looping.
• Disadvantages:
o Time consuming.
o Difficult to modify.
o Very difficult to draw flowchart for big or complex problems.
• Draw a flowchart to accept N numbers and count how many of them were
odd and compute sum of all these odd.
6. ALGORITHM
• An algorithm is a finite and ordered sequence of steps for solving a problem in a
systematic manner.
• It is also called as a step-by-step solution of the problem.
• Advantages:
o Easy to write.
o Human readable techniques to understand logic.
o Algorithms for big problems can be written with moderate efforts.
• Disadvantages:
o Difficult to debug.
o Difficult to show branching and looping.
o Jumping (goto) makes it hard to trace some problems.
Step 1: Start
Step 2: input two numbers: a, b
Step 3: calculate Sum = a + b
Step 4: print “total=”, sum
Step 5: stop
Step 1: Start
Step 2: input length : len
Step 3: calculate area = len * len
Step 4: print “area =”, area
Step 5: stop
Step 1: Start
Step 2: input three numbers: a, b, c
Step 3: calculate sum = a + b + c
Step 1: Start
Step 2: input number: num
Step 3: Check if num < 0 then go to step 6
Step 4: print “positive”
Step 5: stop
Step 6: print “negative”
Step 7: stop
• Write an algorithm to find out minimum number from three input numbers.
Step 1: Start
Step 2: input three numbers: a, b, c
Step 3: if a < b then go to next step otherwise (else) go to step 9
Step 4: if a < c then go to next step else go to step 7
Step 5: print “minimum =”, a
Step 6: stop
Step 7: print “minimum =”, c
Step 8: stop
Step 9: if b < c then go to next step else go to step 12
Step 10: print “minimum =”, b
Step 11: stop
Step 12: print “minimum =”, c
Step 13: stop
Step 1: Start
Step 2: input number: num
Step 3: i = 1
Step 4: f = 1
Step 5: repeat from step 6 to step 7 until i <= num
Step 6: f = f * I
Step 7: i = i + 1
Step 8: print “factorial =”, f
Step 9: stop
Step 1: Start
Step 2: input number: num
Step 3: sum = 0
Step 4: repeat from step 5 to step 7 until num > 0
Step 5: calculate r = num % 10
Step 6: calculate sum = sum * 10 + r
Step 7: calculate num = num / 10
Step 8: print “reverse number =”, sum
Step 9: stop
Step 1: Start
Step 2: input number: num
Step 3: f = 1
Step 4: sum = 0
Step 5: I = 1
Step 6: repeat from step 7 to step 8 until I <= num
Step 7: f = f * I
Step 8: sum = sum + f
Step 9: I = I + 1
Step 10: print “sum =”, sum
Step 11: stop
Step 1: Start
Step 2: input number: num
Step 3: sum = 0, temp = num // store num to temp