Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exercise (1).

Similar presentations


Presentation on theme: "Exercise (1)."— Presentation transcript:

1 Exercise (1)

2 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

3 Flow chart Start or Stop Program Input or Output
Process, Calculate, Storage Used to express logical operations or operations report (Condition) Arrows determine the direction of the program's progress Connection

4 Flow chart start Input : stop Sum = T1+T2+T3 Avg = sum/3 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 Processing : Sum = T1+T2+T3 Avg = sum/3 Output: Sum = T1+T2+T3 Avg = sum/3 Print avg stop

5 Note: (if X=0 enter value of X again)
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) Flow Chart start Input X If X=0 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 yes No Y=(X-2)/X Print Y stop

6 Flow chart Example: start Stop
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 Start Input T1,T2,T3 Sum = T1+T2+T3 Avg = sum/3 If avg > 15 then Print avg Else Print “cold” End if end Avg = sum/3 No Yes avg > 15 Print “cold” Print avg Stop

7 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.

8 Answer : End Yes No Yes Print cool No Print moderate Print hot
If avg<15 Yes No If avg<25 Yes Print cool No Print hot Print moderate End

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)

10 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

11 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 Input r π × r × A= r Print A End Input R Process Π = 3.14 A= π × R × R output Print A End Pseudo code π = 3.14

12 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 C= 2* (L+W) start Input L,W Print International End Start Input L , W C= 2× ( L + W) If c ≥ 600 then Print “ international” Else Print “ local” End if print c End No If C>=600 Yes Print Local

13 Formulate resolve the matter to find the zakaah and that if you know money saver and you know that zakaah = × 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 M>1000 no yes K=M*0.025 Print k stop

14 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

15 Write a program that accept an integer from the user and print it is Positive or Negative number.

16 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.

17 start 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. Enter number (n) yes n>0 Print “positive” No yes N<0 Print “negative” No print “equal zero” end


Download ppt "Exercise (1)."

Similar presentations


Ads by Google