Problem Solving using Computers
Introduction to Problem-Solving using Computers
• Problem solving is a
process of transforming the description of a problem into the solution.
• Computer based
problem solving is a systematic process of designing, implementing and using
programming tools.
• Set of steps
that a machine can perform for solving a problem.
The following six
steps must be followed to solve a problem using computer.
1.
Problem Analysis
2.
Program Design - Algorithm, Flowchart
and Pseudocode
3.
Coding
4.
Compilation and Execution
5.
Debugging and Testing
6.
Program Documentation
What is an Algorithm?
In computer programming terms, an algorithm is a
set of well-defined instructions to solve a particular problem. It takes a set
of input(s) and produces the desired output. For example,
An algorithm to add two numbers:
1.
Take two number inputs
2.
Add numbers using the + operator
3.
Display the result
Algorithm
1: Add two numbers entered by the user
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
Algorithm
2: Find the largest number among three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
Algorithm
3: Find the factorial of a number
Step 1: Start
Step 2: Declare variables n, factorial and i.
Step 3: Initialize variables
factorial ← 1
i ← 1
Step 4: Read value of n
Step 5: Repeat the steps until i = n
5.1: factorial ← factorial*i
5.2: i ← i+1
Step 6: Display factorial
Step 7: Stop
Algorithm
4: Check whether a number is prime or not
Step 1: Start
Step 2: Declare variables n, i, flag.
Step 3: Initialize variables
flag ← 1
i ← 2
Step 4: Read n from the user.
Step 5: Repeat the steps until i=(n/2)
5.1 If remainder of n÷i equals 0
flag ← 0
Go to step 6
5.2 i ← i+1
Step 6: If flag = 0
Display n is not prime
else
Display n is prime
Step 7: Stop
Algorithm
5: Find the Fibonacci series till the term less than 1000
Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term ← 0 second_term ← 1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term ≤ 1000
5.1: temp ← second_term
5.2: second_term ← second_term + first_term
5.3: first_term ← temp
5.4: Display second_term
Step 6: Stop
Flowcharts
What is a Flowchart?
Flowchart is a graphical representation of an
algorithm. Programmers often use it as a program-planning tool to solve a
problem. It makes use of symbols which are connected among them to indicate the
flow of information and processing.
The process of drawing a flowchart for an
algorithm is known as “flowcharting”.
Draw flowchart for Calculating average of two numbers |
||
|
||
|
||
|
||
0 comments:
Post a Comment