1 / 21

Algorithm & Flow Charts Week 1

Learn about algorithms and flowcharts through step-by-step methods for solving problems. Includes examples for addition, multiplication, subtraction, finding averages, and more. Practice drawing flowcharts for various scenarios to enhance problem-solving skills.

callicoat
Download Presentation

Algorithm & Flow Charts Week 1

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. Algorithm & Flow ChartsWeek 1 Presented ByManesh TCourse:1090 CS

  2. ALGORITHMS AND FLOWCHARTS • Algorithm • Step by step method to solve a problem is algorithm • Flow Chart • Diagrammatic representation of algorithm

  3. Algorithm • Example 1: Write an algorithm to Add two numbers

  4. Problem: Add two numbers Step 1: Start Step 2: Read A, B Step 3: C=A+B Step 4: Print C Step 5: Stop

  5. Algorithm Problem: Multiply 2 numbers Problem: Subtract 2 numbers Step 1: Start Step 2: Read A, B Step 3: C=A-B Step 4: Print C Step 5: Stop Step 1: Start Step 2: Read A, B Step 3: C=A*B Step 4: Print C Step 5: Stop

  6. AlgorithmProblem: Average of 3 numbers Step 1: Start Step 2: Read A, B, C Step 3: Avg=(A+B+C)/3 Step 4: Print Avg Step 5: Stop

  7. AlgorithmProblem: Find your Age Step 1: Start Step 2: Read Byear Step 3: Age=2015-Byear Step 4: Print Age Step 5: Stop

  8. AlgorithmProblem: Area of Circle Step 1: Start Step 2: Read Radius Step 3: Area=3.14*Radius *Radius Step 4: Print Area Step 5: Stop

  9. AlgorithmProblem: Find even or odd Step 1: Start Step 2: Read N Step 3: Is (N%2=0) then Print “Even” else Print “Odd” Step 4: Stop

  10. AlgorithmProblem: Find Pass or Fail • Detailed Algorithm • Step 1: Start • Step 2: Read Mark Step 3: Is (Mark>=60) then Print “PASS” else Print “Fail” Step 4: Stop

  11. The Flowchart A Flowchart is another algorithm but graphical. • shows logic solution • emphasizes individual steps and their interconnections • A flowchart must have a start and stop • A steps in a flowchart must connect.

  12. Flowchart Symbols General Used Symbols

  13. Flow Chart: Add Two Numbers Algorithm Start Flowchart Read A, B C=A+B Print C Stop

  14. DECISION STRUCTURES • The expression A>B is a logical expression • it describes a condition we want to test • if A>B is true (if A is greater than B) we take the action on left • print the value of A • if A>B is false (if A is not greater than B) we take the action on right • print the value of B

  15. is A>B Y N DECISION STRUCTURES Print A Print B

  16. Flow Chart: Find Even or Odd Start Read N Is N%2=0 N Y Print “Odd” Print “Even” Stop

  17. Flow Chart: Find Largest of two numbers Start Read A, B Is A>B N Y Print “B is large” Print “A is large” Stop

  18. START Read a, b, c d sqrt(b x b – 4 x a x c) x1(–b + d) / (2 x a) X2 (–b – d) / (2 x a) STOP Problem: Write Algorithm and Flowchart to find solution of Quadratic equation • Algorithm: • Step 1: Start • Step 2: Read a, b, c • Step 3: dsqrt ( ) • Step 4: x1  (–b + d) / (2 x a) • Step 5: x2  (–b – d) / (2 x a) • Step 6: Print x1, x2 • Step 7: Stop Print X1, X2

  19. Assignment 1 Draw algorithm and flowchart • Find area of triangle (area=(1/2)*breadth*height) • Convert Celsius to Fahrenheit temperature f = (1.8*c) + 32; • Volume of cylinder(V= 3.14*R*R*Height) • Find volume of sphere (4/3* 3.14*R*R*R) • Find biggest of three numbers.

  20. Instructions to students Study definition well Study different algorithms well Study how to draw flowchart for specific problems. Workout various assignment problems Approach me for any doubt clarifications

  21. Control Statements Decision Making & Branching Decision Making & Looping If Statement Switch ConditionalStatement For loop While loop Do while loop Jump Break Continue Simple If If else Nested if else If else ladder

More Related