lecture 1
lecture 1
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
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
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