1 / 14

Basic Control Structures

Basic Control Structures. Sequence Selection Repetition. Sequence. A process executed from one to another in a straightforward manner. Start. Read N. Print N. End. Example of Sequence. Design a flowchart that will accept and display a number. Write its equivalent algorithms.

rodgersb
Download Presentation

Basic Control Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Control Structures Sequence Selection Repetition

  2. Sequence • A process executed from one to another in a straightforward manner.

  3. Start Read N Print N End Example of Sequence • Design a flowchart that will accept and display a number. Write its equivalent algorithms. Algorithm: Step 1: Read in the value of N. Step 2: Print the value of N.

  4. Start Sum=0 Product=0 Read A,B Sum=A+B Product=A*B Print Sum, Product End Example of Sequence 2. Draw a flowchart that will compute and display the sum and product of two numbers. Write its equivalent algorithm. Algorithm: Step 1:Initialize Sum and Product into 0. Step 2: Read in the values of A and B. Step 3. Compute Sum by adding A and B then compute Product by multiplying A and B. Step 4: Print the computed value of Sum and Product.

  5. A C B Selection (if – then – else) • A choice is provided between alternatives. T F

  6. Example of Selection • Draw a flowchart that will input values for A and B. Compare two values inputted and print which of the values is higher including the remarks “Higher”. Write its equivalent algorithm.

  7. Start Input A, B A > B Print A, “Higher” Print B, Higher End Algorithm: Step 1: Read in the values of A and B. Step 2: Test if A is greater than B, A is higher. However, If A is less than B, B is higher. Step 3: Print the number and the remark “Higher”. T F

  8. Repetition (Looping) • This structure provides for the repetitive execution of an operation or routine while the condition is true. The condition is evaluated before executing any process statement. As long as the condition is true, the process is executed, otherwise, control flows out of the structure.

  9. C F T Loop A

  10. Example of Repetition (Looping) Construct a flowchart that will count from 1 to 10 and print each number counted using the do-while-repetition structure .Write its equivalent algorithm.

  11. Start C=0 C < 10 F End T C = C + 1 Print C Example of Repetition (Looping) Algorithm: Step 1: Initialize the value of C to 0. Step 2: Test if C is less than 10. Step 3: If C is less than 10, add 1 to the value of C, print the value then go back to Step 2. However, if C is greater than 10, stop processing.

  12. Commonly Used Operators in Flowcharting Arithmetic Operators + addition - Subtraction * Multiplication / Division

  13. Commonly Used Operators in Flowcharting Relational Operators = equal > Greater than < less than <> Not equal > Greater than or equal to < less than or equal to

  14. Commonly Used Operators in Flowcharting Logical operators && AND || OR ! NOT

More Related