0% found this document useful (0 votes)
51 views

Algorithms and Flowcharts

The document discusses algorithms and flowcharts. It defines an algorithm as an ordered sequence of steps to solve a problem. Key features of algorithms are that they should be simple, unambiguous, lead to a unique solution, and involve a finite number of steps. It provides examples of algorithms to calculate a student's grade, convert feet to centimeters, calculate the area of a rectangle, and find the roots of a quadratic equation. The last example also describes the corresponding flowchart to add a series of test scores.

Uploaded by

Raj Bren
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Algorithms and Flowcharts

The document discusses algorithms and flowcharts. It defines an algorithm as an ordered sequence of steps to solve a problem. Key features of algorithms are that they should be simple, unambiguous, lead to a unique solution, and involve a finite number of steps. It provides examples of algorithms to calculate a student's grade, convert feet to centimeters, calculate the area of a rectangle, and find the roots of a quadratic equation. The last example also describes the corresponding flowchart to add a series of test scores.

Uploaded by

Raj Bren
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

ALGORITHMS AND FLOWCHARTS

ALGORITHMS AND FLOWCHARTS


A typical programming task can be divided into two phases: Problem solving phase
produce

an ordered sequence of steps that describe solution of problem this sequence of steps is called an algorithm

Implementation phase
implement

the program in some programming

language

Algorithm
Algorithm is a procedure for performing some calculation. Algorithm gives the logic of a program that is a step by step description of how to arrive at a solution. An effective way for solving a problem in finite number of steps.

Key Features of Algorithm

It should be simple.
It should be clear with no ambiguity.

It should lead unique solution of the problem.


It should involve finite number of steps.

It should have the capability to handle some unexpected situations which may arise during the solution of a problem(for eg: Division with zero).

Algorithm

Example 1: Write an algorithm to determine a students final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

Algorithm
Algorithm: Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print FAIL else Print PASS

Example 2

Write an algorithm to convert the length in feet to centimeter.

Input the length in feet (Lft) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM)

Example 3
Write an algorithm that will read the two sides of a rectangle and calculate its area.

Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A

Example 4

Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation ax 2 bx c 0

b2 4ac ), and the roots are: Hint: d = sqrt (


x1 = (b + d)/2a and x2 = (b d)/2a

Example 4
Algorithm: Input the coefficients (a, b, c) of the quadratic equation Calculate d Calculate x1 Calculate x2 Print x1 and x2

Example 5.
Design an algorithm and the corresponding flowchart for adding the test scores as given below: 26, 49, 98, 87, 62, 75

1.

Start 2. Sum = 0 3. Get a value 4. sum = sum + value 5. Go to step 3 to get next Value 6. Output the sum 7. Stop

You might also like