Input T1, T2, T3

Download Report

Transcript Input T1, T2, T3

Exercise (1)
Example:
- Using Pseudo code, Write suitable algorithm:
- Calculate and print the average temperature, readings for the
degrees as the following T1, T2, T3.
Input T1, T2, T3
avg= (T1 + T2 + T3)/3
Print avg
Input T1, T2, T3
Sum = (T1 + T2 + T3)
Avg = sum/3
Print avg
2
Flow chart
Start or Stop Program
Input or Output
Process, Calculate, Storage
Used to express logical operations
or operations report (Condition)
Connection
Arrows determine the direction of the
program's progress
Flow chart
-
Example :
Using flow chart, Write suitable algorithm:
Calculate and print the average temperature
for the following readings T1, T2, T3.
start
Input
T1, T2, T3
Input :
T1, T2, T3
Sum = T1+T2+T3
Avg = sum/3
Print
avg
stop
Processing :
Sum = T1+T2+T3
Avg = sum/3
Output:
Avg = sum/3
Using pseudo code and flow chart to
write an algorithm. Enter number (X)
and then find and print the value (Y),
as shown in the following equation:
Y=(X-2)/X
Note: (if X=0 enter value of X again)
Pseudo code
input X
process if x=0 Re-enter the new value of
x because you can not divide by 0 “
Y=(X-2)/X
output Y
Flow Chart
start
Input X
yes
If X=0
No
Y=(X-2)/X
Print Y
stop
Flow chart
Example:
start
-
input
T1, T2, T3
-
Using flow chart, Write suitable algorithm:
Calculate and print the average
temperature. Readings as the following T1,
T2, T3.
IF the average is greater than 15 print the
average, else print the weather is cold.
Start
Input T1,T2,T3
Sum= T1+T2+T3
Avg = sum/3
Sum = T1+T2+T3
Avg = sum/3
No
Yes
If avg > 15 then
avg > 15
Print avg
Print “cold”
Print avg
Else
Print “cold”
End if
end
Stop
Discuss
Write an algorithm using pseudo code and flow chart for the
introduction of 3 degrees and find the average temperature and print
the "cool air“ if temperature less than 15, Print "moderate air” if
temperature between 15 and 25, and print “hot air” if the
temperature not verify the previous conditions.
7
Answer :
No
No
Print hot
If avg<15
Yes
Yes
If avg<25
Print moderate
End
Print cool

9
Using pseudo code and flow chart to write an algorithm to calculate
the area and perimeter of ​a rectangle.
Note: the area of ​the rectangle = length × width.
Perimeter = 2*(length+width)
 Using pseudo code and flow chart to write an algorithm to calculate and
print the area of a right-angled triangle .
The base of the triangle = a
The height of triangle= b
Equation of area= (1/2)*a*b
Write a program using the pseudo code and flow chart to
find the area of ​a circle which radius R print it.
Note: The area of ​a circle is equal to π * R2, where π is a
constant value of approximately 3.14.
flow chart
start
Pseudo
code
Input r
π = 3.14
A= r × r × π
Print A
End
Input R
Process
Π = 3.14
A= π × R × R
output
Print A
End
Using the methods (pseudo code and flow chart), we need to find and
print the vicinity of the football stadium, and determine whether
international (greater than or equal to 600 m) or local (less so),
Note: The perimeter of the rectangle is equal to (length + width) × 2 .
flow chart
Start
Input L , W
start
Input L,W
C= 2 × ( L + W)
C= 2* (L+W)
If c ≥ 600 then
Print “ international”
Print Local
No
Yes
If C>=600
Else
Print “ local”
End if
print c
End
End
Print
Internationa
l
Formulate resolve the matter to find the zakaah and that if you know money
saver and you know that zakaah = 0.025 × money saver, provided the account
of zakaah money if it exceeds 1000 SR
Flow chart
start
Pseudo code
Input
money m
Process
If m>1000 calculate zakaah else do not calculate zakaah
zakaah=0.025*money
Output
print zakaah
Input M
no
M>1000
yes
K=M*0.025
Print k
stop
Formulate a solution to print the odd numbers from 1 to 49 ?
Pseudo code
Output: print output from 1 to 49
Input: no input
Process: transfer from odd number to odd number
no=1
Print no
no=no+2
If no>50 then stop else go to step (2)
Flow chart
start
No=1
Print No
No=No+2
no
No>50
yes
stop
 Write a program that accept an integer from the user and
print it is Positive or Negative number.
 Write a program that accept an integer from the user and test the number . If it is
positive print Positive, if it is negative print Negative if equal zero print equal zero.
start
Enter number (n)
yes
Print “positive”
No
yes
Print “negative”
n>0
N<0
No
print “equal zero”
end
Use flow chart to write
algorithm. Read an integer
from the user and test then
number . If it is positive print
Positive, if it is negative print
Negative if equal zero print
equal zero.