0% found this document useful (0 votes)
4 views

lecture 1

The document provides an introduction to algorithms and flowcharts, defining algorithms as finite sequences of effective statements to solve problems. It includes examples of algorithms for finding maximum numbers, summing numbers, and calculating averages, as well as flowcharts illustrating these processes. The lecture emphasizes the properties of algorithms, such as finiteness, non-ambiguity, and effectiveness.

Uploaded by

jafar.bh200
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)
4 views

lecture 1

The document provides an introduction to algorithms and flowcharts, defining algorithms as finite sequences of effective statements to solve problems. It includes examples of algorithms for finding maximum numbers, summing numbers, and calculating averages, as well as flowcharts illustrating these processes. The lecture emphasizes the properties of algorithms, such as finiteness, non-ambiguity, and effectiveness.

Uploaded by

jafar.bh200
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
You are on page 1/ 13

Lecture 1

Algorithms and Flowcharts

Prof.Dr. Ashwaq Alabaichi


[email protected]
[email protected]
Algorithm:
algorithm can be defined as a finite sequence of effect
statements to solve a problem. An effective statement is
a clear, unambiguous instruction that can be carried out.
Algorithm properties:
• Finiteness: the algorithm must terminate a finite
number of steps.
• Non-ambiguity: each step must be precisely defined.
At the completion of each step in the nest step
should be uniquely determined .
• Effectiveness: the algorithm should solve the
problem in a reasonable amount of time.
Cont…
Ex1:Write algorithm to find maximum number from two numbers.
1. start
2. input two numbers(num1 and num2)
3. if num1 greater than num2 print num1
4. if num2 greater than num1 print num2
5. end
Ex2: Write algorithm to sum two numbers
1. Start
2. Input first number
3. Input second number
4. Calculate the sum
5. Print the result
6. end
Ex3 Write algorithm to find the division two numbers

1. Start
2. Input first number
3. Input second number
4. If second number not equal 0 Goto 6
5. If second number equal 0 Goto 9
6. Calculate division
7. Print the result
8. Goto 10
9. Print error
10. end
Count…
• Ex 4:Write algorithm to find the sum of negative numbers among 50
numbers.
1. Start
2. Initialize two variables (counter and sum), set counter to 1 ,sum to 0
3. Input number.
4. if the counter greater than 50 go to 10
5. If the number is less than zero go to 7
6. go to 8
7. Add the number to the sum.
8. increment the counter of input numbers by 1
9. Go to 3
10. print sum
11. End
Count…
ex5 write an algorithm that inputs a n of number and output their average
- Input n
- Input a number.
- Add a number to another number to find sum .
- Divide sum on n.
- Output average.
Thus an algorithm is:
1. start.
2. Set counter to 1, sum to zero
3. Input the number of entered numbers which is n
4. if the counter greater than n go to 9
5. Input number.
6. Add the number to the sum.
7. increment the counter of enter numbers.
8. go to 4
9. Average =sum /n.
10. print average
11. End
• A flowchart is a graphical representation of an algorithm or of a portion of
an algorithm .Flowcharts are drawn using symbols. The main symbols used
to draw a flowchart are shown in following figure
Ex1:Draw the flowchart of maximum number between two
numbers
start

Enter
num1,num2

Is yes
no num1>
num2

print num2 Print num1

end
Ex2: draw the flowchart of sum two numbers

start

Enter number a

enter number b

Sum=a+b

Output sum

end
Ex3: draw the flowchart of the division of two numbers

start

Input num1 &


num2

yes Is
no
num2=
0
result=num1/num2
Print error
Print result

end
start
ex4 :draw the flowchart to find the
sum of negative numbers among 50 Sum=0
numbers. Counter=1

Is no
counter<
= 50
yes
Input number

Is no
number<
0
yes

sum=sum + number

counter=counter+ 1

print sum

end
example 5 draw flowchart of average n numbers
start
Sum=0,C=0
sum=0, i=1

input n
no
Is i< =n
yes
input number

sum=sum+number

i=i+1

Av=sum/n

print AV

ende
• HW// Write algorithm and draw flowchart to read 3 numbers and print the largest
number of them.
• Find the output of the flowchart

You might also like