ALGORITHM Step 1 Input VALUE1 VALUE2 Step 2 if VALUE1 VALUE2 then MAX VALUE1

Algorithm step 1 input value1 value2 step 2 if value1

This preview shows page 27 - 36 out of 36 pages.

ALGORITHM Step 1: Input VALUE1, VALUE2 Step 2: if ( VALUE1 > VALUE2) then MAX VALUE1 else MAX VALUE2 endif Step 3: Print “The largest value is”, MAX
Image of page 27
Example 5 MAX VALUE1 Print “The largest value is”, MAX STOP Y N START Input VALUE1,VALUE2 MAX VALUE2 is VALUE1>VALUE2
Image of page 28
NESTED IFS One of the alternatives within an IF– THEN–ELSE statement may involve further IF–THEN–ELSE statement
Image of page 29
Example 6Write an algorithm that reads threenumbers and prints the value of the largest number.
Image of page 30
Example 6 Step 1: Input N1, N2, N3 Step 2: if ( N1>N2) then if ( N1>N3) then MAX N1 [N1>N2, N1>N3] else MAX N3 [N3>N1>N2] endif else if ( N2>N3) then MAX N2 [N2>N1, N2>N3] else MAX N3 [N3>N2>N1] endif endif Step 3: Print “The largest number is”, MAX
Image of page 31
Example 6 Flowchart: Draw the flowchart of the above Algorithm.
Image of page 32
Example 7Write and algorithm and draw a flowchart to a)read an employee name (NAME), overtime hours worked (OVERTIME), hours absent (ABSENT) andb)determine the bonus payment (PAYMENT).
Image of page 33
Example 7 Bonus Schedule OVERTIME – (2/3)*ABSENT Bonus Paid >40 hours >30 but 40 hours >20 but 30 hours >10 but 20 hours 10 hours $50 $40 $30 $20 $10
Image of page 34
Step 1: Input NAME,OVERTIME,ABSENT Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then PAYMENT 50 else if ( OVERTIME–(2/3)*ABSENT > 30) then PAYMENT 40 else if ( OVERTIME–(2/3)*ABSENT > 20) then PAYMENT 30 else if ( OVERTIME–(2/3)*ABSENT > 10) then PAYMENT 20 else PAYMENT 10 endif Step 3: Print “Bonus for”, NAME “is $”, PAYMENT
Image of page 35
Example 7Flowchart: Draw the flowchart of the above algorithm?
Image of page 36

You've reached the end of your free preview.

Want to read all 36 pages?

  • Fall '18
  • Abdul Umar
  • Pseudocode & Algorithm,  Input

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture