Algorithm Flow Charts Week 1 Presented By Manesh

Algorithm & Flow Charts Week 1 Presented By Manesh T Course: 1090 CS

ALGORITHMS AND FLOWCHARTS n Algorithm ¨ Step n by step method to solve a problem is algorithm Flow Chart ¨ Diagrammatic representation of algorithm

Algorithm Example 1: Write an algorithm to Add two numbers n

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

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

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

Algorithm Problem: Find your Age Step 1: Step 2: Step 3: Step 4: Step 5: Start Read Byear Age=2015 -Byear Print Age Stop

Algorithm Problem: Area of Circle Step 1: Step 2: Step 3: Step 4: Step 5: Start Read Radius Area=3. 14*Radius Print Area Stop

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

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

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.

Flowchart Symbols General Used Symbols

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

DECISION STRUCTURES n n n 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

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

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

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

Problem: Write Algorithm and Flowchart to find solution of Quadratic equation START n Algorithm: n Step 1: Step 2: Step 3: Step 4: Step 5: Step 6: Step 7: n n n Start Read a, b, c d sqrt ( x 1 (–b + d) / (2 x a) x 2 (–b – d) / (2 x a) Print x 1, x 2 Stop Read a, b, c ) d sqrt(b x b – 4 x a x c) x 1 (–b + d) / (2 x a) X 2 (–b – d) / (2 x a) Print X 1, X 2 STOP

Assignment 1 Draw algorithm and flowchart 1. 2. 3. 4. 5. 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.

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

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