Introduction To Computers and Programming (CSE 101) : Dr. Ruhul Amin., Asst. Prof., CSE, NIT Jamshedpur
Introduction To Computers and Programming (CSE 101) : Dr. Ruhul Amin., Asst. Prof., CSE, NIT Jamshedpur
ICP-PART-2
Problem solving -Introduction
Step 1: Start
Step 2: Initialize factorial to be 1, i to be 1
Step 3: Input a number n
Step 4: Check whether the number is 0. If so report factorial
is 1 and goto step 9
Step 5: Repeat step 6 through step 7 n times
Step 6: Calculate factorial = factorial * i
Step 7: Increment i by 1
Step 8: Report the calculated factorial value
Step 9: Stop
To find the sum of N natural numbers
Step 1: Start
Step 2: Declare i,n & sum of integer type.
Step 3: Set sum to zero.
Step 4: Read value of n.
Step 5: Set i to 1.
Step 6: Add current value of i to sum.
Step 7: Repeat step 6 until i reaches to n.
Step 8: Print sum.
Step 9: End.
to find the sum of even & odd numbers.
Step 1: Start
Step 2: Declare n,i,evensum & addsum of integer type.
Step 3: Set evensum & oddsum to zero.
Step 4: Read value of n.
Step 5: Set i to 1.
Step 6: Check whether the number is divisable by 2 or not.
If yes add current value of i to evensum otherwise add to
oddsum.
Step 8: Repeat step 6 until i reatches to n.
Step 9: Print evensum & oddsum.
Step 10: End.
Measuring Performance
These are particularly useful for small These are useful for detailed
problems representations of complicated programs
For complex programs, algorithms prove For complex programs, Flowcharts prove
to be Inadequate to be adequate
Symbols used in Flow-Charts
Contd..
Flowchart to illustrate how to make a
Land phone telephone call
Flowchart to find the factorial of given
positive integer N.
Adding the integers from 1 to 100 and
to print the sum.
Pseudo code
● Expressed in binary.
– 10110100 may mean ADD, 01100101 may mean SUB, etc.
● Directly understood by the computer.
● Not portable; varies from one machine type to another.
– Program written for one type of machine will not run
on another type of machine.
● – Difficult to use in writing programs.
Assembly Language
Program edited in
Phase 1 Editor Editor and stored
Disk
on disk
Preprocessor
Phase 2 Preprocessor
Disk program processe
the code
Phase 5 Loader
Puts program in
memory
Sample programs