Modules-1 Problem Solving Using Java (CSE 1004)
Modules-1 Problem Solving Using Java (CSE 1004)
Module 1 :
Introduction to Problem Solving
A computer is an electronic
device that manipulates
information or data. It has the
ability to store, retrieve, and
process data.
Characteristics of Computers
1. Hardware
Hardware is basically anything that you can touch with
your fingers.
2. Software
For computer hardware to work it must follow a set of
instructions that is supplied to it as software.
Hardware
Hardware
1. System Software
25 = 00011001 =
The number 179 stored as 8 bits using the binary number system:
179 = 10110011 =
The letter A stored as 8 bits using American Standard Code for Information
Interchange code:
A = 01000001 =
Information for the Exam
INPUT
PROCESSING
OUTPUT
Exam Results!
PC four major functions are:
Input data
Process data
Output information
Store data and information
DATA IN
INFORMATION
OUT
So
Computer is an Electronic device which can:
1. accept data
2. process it
Country-Malaysia
• Binary
0 or 1
• Octal
0-7
• Hexadecimal
0-9+A-F
• Decimal
0-9
ALGORITHMS ANDFLOWCHARTS
Introduction
3. Develop an Algorithm
• An algorithm is the sequence of operations to be
performed.
• It gives the precise plan of the problem.
Example: TO FIND THE AVERAGE OF TWO NUMBERS.
Algorithm:
1. Set the sum of the data values to 0.
2. Set the count of the data values to zero.
3. As long as the data values exist, add the next data value
to the sum and add 1 to the count.
Continue…..
Computer Program ?
Set of instructions to perform some specific task
Is Program itself a Software ?
NO, Program is small part of software.
Software merely comprises of Group of Programs (Source
code),
Code: refers to statements that are written in any
programming language as machine code or C code.
•Code is some time interchangeably used with program.
2
Program design
Problem Program
Algorithm
Informal definition of algorithm
Algorithms
24
Flowchart (cont..)
25
Write algorithm to add two numbers
• Step 1: Start
• Step 2: Take two numbers a, b and Sum for result
• Step 3: Enter two numbers a and b
• Step 4: Sum <- a + b
• Step 5: Display Sum
• Step 6: Stop
NOTE :
• An algorithm is a step by step procedure to solve a particular problem
whereas a program is an algorithm that is encoded in any programming
language.
• Program is language dependent and algorithm is language independent.
Flowchart (Cont..)
n = 4562
sum = 0
• r = n % 10 = 4562 % 10 = 2
• sum = sum *10 + r = 2
n = n/10 = 456
• sum = sum *10 + r = 20 + 6 = 26
n = n/10 = 45
• sum = sum *10 + r = 260 + 5 = 265
n = n/10 = 4
• sum = sum *10 + r = 2650 + 4 = 2654
n = n/10 = 0
Flowchart of Reversing the digits of integer