ALGORITHM & FLOWCHART MANUAL For STUDENTS

3y ago
155 Views
27 Downloads
735.02 KB
25 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Jayda Dunning
Transcription

Algorithm & Flowchart ManualALGORITHM & FLOWCHART MANUALforSTUDENTS(Ravi K. Walia)Assistant Professor & InchargeComputer & Instrumentation CentreDr. Y. S. Parmar University of Horticulture & Forestry,Nauni Solan INDIA (HP)1CIC-UHF

Algorithm & Flowchart ManualPREFACEThis document has been prepared for students at Dr. Y. S. Parmar University of Horticulture& Forestry, Nauni, Solan (HP) India. Software Engineer uses various programminglanguages to create programs. Before writing a program, first needs to find a procedure forsolving the problem. The program written without proper pre-planning has higher chances oferrors.Algorithm and flowchart are the powerful tools for learning programming. An algorithm is astep-by-step analysis of the process, while a flowchart explains the steps of a program in agraphical way. Algorithm and flowcharts helps to clarify all the steps for solving the problem.For beginners, it is always recommended to first write algorithm and draw flowchart forsolving a problem and then only write the program.Beginners find it difficult to write algorithm and draw flowchart. The algorithm can vary fromperson to person to solve a particular problem. The manual will be useful for the students tolearn algorithm and flowchart. It includes basics of algorithm and flowchart along withnumber of examples. Software ClickCharts by NCH (unlicensed version) has been used todraw all the flowcharts in the manual.2CIC-UHF

Algorithm & Flowchart Manual.ALGORITHM:The word “algorithm” relates to the name of the mathematician Al-khowarizmi, which meansa procedure or a technique. Software Engineer commonly uses an algorithm for planningand solving the problems. An algorithm is a sequence of steps to solve a particular problemor algorithm is an ordered set of unambiguous steps that produces a result and terminates ina finite timeAlgorithm has the following characteristics Input: An algorithm may or may not require input Output: Each algorithm is expected to produce at least one result Definiteness: Each instruction must be clear and unambiguous. Finiteness: If the instructions of an algorithm are executed, the algorithmshould terminate after finite number of stepsThe algorithm and flowchart include following three types of control structures.1. Sequence: In the sequence structure, statements are placed one after the other andthe execution takes place starting from up to down.2. Branching (Selection): In branch control, there is a condition and according to acondition, a decision of either TRUE or FALSE is achieved. In the case of TRUE, oneof the two branches is explored; but in the case of FALSE condition, the otheralternative is taken. Generally, the ‘IF-THEN’ is used to represent branch control.3. Loop (Repetition): The Loop or Repetition allows a statement(s) to be executedrepeatedly based on certain loop condition e.g. WHILE, FOR loops.Advantages of algorithm It is a step-wise representation of a solution to a given problem, which makes it easyto understand. An algorithm uses a definite procedure. It is not dependent on any programming language, so it is easy to understand foranyone even without programming knowledge. Every step in an algorithm has its own logical sequence so it is easy to debug.3CIC-UHF

Algorithm & Flowchart ManualHOW TO WRITE ALGORITHMSStep 1 Define your algorithms input: Many algorithms take in data to be processed, e.g.to calculate the area of rectangle input may be the rectangle height and rectangle width.Step 2 Define the variables: Algorithm's variables allow you to use it for more than oneplace. We can define two variables for rectangle height and rectangle width as HEIGHT andWIDTH (or H & W). We should use meaningful variable name e.g. instead of using H & Wuse HEIGHT and WIDTH as variable name.Step 3 Outline the algorithm's operations: Use input variable for computation purpose,e.g. to find area of rectangle multiply the HEIGHT and WIDTH variable and store the value innew variable (say) AREA. An algorithm's operations can take the form of multiple steps andeven branch, depending on the value of the input variables.Step 4 Output the results of your algorithm's operations: In case of area of rectangleoutput will be the value stored in variable AREA. if the input variables described a rectanglewith a HEIGHT of 2 and a WIDTH of 3, the algorithm would output the value of 6.FLOWCHART:The first design of flowchart goes back to 1945 which was designed by John Von Neumann.Unlike an algorithm, Flowchart uses different symbols to design a solution to a problem. It isanother commonly used programming tool. By looking at a Flowchartone can understand theoperations and sequence of operations performed in a system. Flowchart is often consideredas a blueprint of a design used for solving a specific problem.Advantages of flowchart: Flowchart is an excellent way of communicating the logic of a program. Easy and efficient to analyze problem using flowchart. During program development cycle, the flowchart plays the role of a blueprint, whichmakes program development process easier. After successful development of a program, it needs continuous timely maintenanceduring the course of its operation. The flowchart makes program or systemmaintenance easier. It is easy to convert the flowchart into any programming language code.4CIC-UHF

Algorithm & Flowchart ManualFlowchart is diagrammatic /Graphical representation of sequence of steps to solve aproblem. To draw a flowchart following standard symbols are useSymbol NameSymbolfunctionUsed to represent start andend of flowchartOvalParallelogramUsed for input and outputoperationRectangleProcessing: Used forarithmetic operations anddata-manipulationsDiamondDecision making. Used torepresent the operation inwhich there are two/threealternatives, true and falseetcArrowsFlow line Used to indicatethe flow of logic byconnecting symbolsCirclePage ConnectorOff Page ConnectorPredefined Process/Function Used to representa group of statementsperforming one processingtask.Preprocessor ---------------------- --------------5CommentsCIC-UHF

Algorithm & Flowchart ManualThe language used to write algorithm is simple and similar to day-to-day life language. Thevariable names are used to store the values. The value store in variable can change in thesolution steps. In addition some special symbols are used as belowAssignment Symbol ( or ) is used to assign value to the variable.e.g. to assign value 5 to the variable HEIGHT, statement isHEIGHT 5orHEIGHT 5The symbol ‘ ’ is used in most of the programming language as an assignment symbol, thesame has been used in all the algorithms and flowcharts in the manual.The statement C A Bmeans that add the value stored in variable A and variable Bthen assign/store the value in variable C.The statement R R 1 means that add I to the value stored in variable R and thenassign/store the new value in variable R, in other words increase the value of variable R by 1Mathematical Operators:OperatorMeaningExample AdditionA B-SubtractionA–B*MultiplicationA*B/DivisionA/ B PowerA 3 for A3%ReminderA%BOperatorMeaningExample Less thanA B Less than or equal toA B or Equal toA B# or ! Not equal toA # B or A ! B Greater thanA B Greater tha or equal toA BRelational Operators6CIC-UHF

Algorithm & Flowchart ManualLogical OperatorsOperatorExampleMeaningANDA B AND B CResult is True if both A B andB C are true else falseORA B OR B CResult is True if either A B orB C are true else falseNOTNOT (A B)Result is True if A B is falseelse trueSelection control StatementsSelection ControlExampleMeaningIF ( Condition ) Then ENDIFIF ( X 10 ) THENY Y 5ENDIFIf condition X 10 is Trueexecute the statementbetween THEN and ENDIFIF ( Condition ) Then ELSE .IF ( X 10 ) THENY Y 5ELSEY Y 8Z Z 3ENDIFIf condition X 10 is Trueexecute the statementbetween THEN and ELSEotherwise execute thestatements between ELSEand ENDIFSelection ControlExampleMeaningWHILE (Condition)DO.ENDDODO . UNTILL (Condition)WHILE ( X 10)DOprint xx x 1ENDDODOprint xx x 1UNTILL ( X 10)Execute the loop as long asthe condition is TRUEENDIFLoop control StatementsExecute the loop as long asthe condition is falseGO TO statement also called unconditional transfer of control statement is used to transfercontrol of execution to another step/statement. . e.g. the statement GOTO n will transfercontrol to step/statement n.Note: We can use keyword INPUT or READ or GET to accept input(s) /value(s) andkeywords PRINT or WRITE or DISPLAY to output the result(s).7CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find the sum of two numbersAlgorithmStep-1 StartStep-2Input first numbers say AStep-3Input second number say BStep-4SUM A BStep-5Display SUMStep-6 StopORAlgorithmStep-1 StartStep-2Input two numbers say A & BStep-3SUM A BStep-4Display SUMStep-5 Stop8CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to convert temperature from Celsius to FahrenheitC : temperature in CelsiusF : temperature FahrenheitAlgorithmStep-1 StartStep-2Input temperature in Celsius say CStep-3F (9.0/5.0 x C) 32Step-4Display Temperature in Fahrenheit FStep-5 StopAlgorithm & Flowchart to convert temperature from Fahrenheit to CelsiusC : temperature in CelsiusF : temperature FahrenheitAlgorithmStep-1 StartStep-2Input temperature in Fahrenheit say FStep-3C 5.0/9.0 (F - 32 )Step-4Display Temperature in Celsius CStep-5 Stop9CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find Area and Perimeter of SquareL : Side Length of SquareAREA : Area of SquarePERIMETER : Perimeter of SquareAlgorithmStep-1 StartStep-2Input Side Length of Square say LStep-3Area L x LStep-4PERIMETER 4 x LStep-5Display AREA, PERIMETERStep-6 StopAlgorithm & Flowchart to find Area and Perimeter of RectangleL : Length of RectangleB : Breadth of RectangleAREA : Area of RectanglePERIMETER : Perimeter of RectangleAlgorithmStep-1 StartStep-2Input Side Length & Breadth say L, BStep-3Area L x BStep-4PERIMETER 2 x ( L B)Step-5Display AREA, PERIMETERStep-6 Stop10CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find Area and Perimeter of CircleR : Radius of CircleAREA : Area of CirclePERIMETER : Perimeter of CircleStartInput Valueof RAlgorithmStep-1 StartStep-2Input Radius of Circle say RStep-3Area 22.0/7.0 x R x RStep-4PERIMETER 2 x 22.0/7.0 x RStep-5Display AREA, PERIMETERAREA 22.0/7.0xRx RPERIMTER 2 X22.0/7.0 x RPr int A REA,PER I M T ERStep-6 StopStopAlgorithm & Flowchart to find Area & Perimeter of Triangle(when three sides are given)A : First Side of TriangleB : Second Side of TriangleC : Third Side of TriangleAREA : Area of TrianglePERIMETER : Perimeter of TriangleAlgorithmStep-1 StartStep-2Input Sides of Triangle A,B,CStep-3S (A B C)/ 2.0Step-4AREA SQRT(S x (S-A) x (S-B) x(S-C))Step-5PERIMETER S1 S2 S3Step-6Display AREA, PERIMETERStep-7 Stop11CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find Simple InterestP : Principle AmountN : Time in YearsR : % Annual Rate of InterestSI : Simple InterestAlgorithmStep-1 StartStep-2Input value of P, N, RStep-3SI (P x N x R)/100.0Step-4Display SI FStep-6 StopAlgorithm & Flowchart to find Compound InterestP : Principle AmountN : Time in YearsR : % Annual Rate of InterestCI : Compound InterestAlgorithmStep-1 StartStep-2Input value of P, N, R CStep-3CI P(1 R/100)N - PStep-4Display CIStep-6 Stop.12CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to Swap Two Numbers using Temporary VariableAlgorithmStep-1 StartStep-2Input Two Numbers Say NUM1,NUM2Step-3Display Before Swap Values NUM1, NUM2Step-4TEMP NUM1Step-5NUM1 NUM2Step-6NUM2 NUM1Step-7Display After Swap Values NUM1,NUMStep-8 StopAlgorithm & Flowchart to Swap Two Numbers without using temporaryvariableAlgorithmStep-1 StartStep-2Input Two Numbers Say A,BStep-3Display Before Swap Values A, BStep-4A A BStep-5B A-BStep-6A A-BStep-7Display After Swap Values A, BStep-8 Stop13CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find the smallest of two numbersAlgorithmStep-1 StartStep-2 Input two numbers sayNUM1,NUM2Step-3 IF NUM1 NUM2 THENprint smallest is NUM1ELSEprint smallest is NUM2ENDIFStep-4 StopAlgorithm & Flowchart to find the largest of two numbersAlgorithmStartStep-1 StartStep-2 Input two numbers sayI nput V alueof NUM1NUM1,NUM2Step-3IF NUM1 NUM2 THENprint largest is NUM1Input Valueof NUM2ELSEprint largest is NUM2PrintLargest isNUM1ENDIFStep-4YesifNUM1 NUM2NoPrintLargest isNUM2StopStop14CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find the largest of three numbersAlgorithmStep-1 StartStep-2 Read three numbers say num1,num2, num3Step-3if num1 num2 then go to step-5Step-4IF num2 num3 THENprint num2 is largestELSEprint num3 is largestENDIFGO TO Step-6Step-5 IF num1 num3 THENprint num1 is largestELSEprint num3 is largestENDIFStep-6 Stop15CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find the largest of three numbers (an another way)AlgorithmStep-1 StartStep-2 Read three numbers say A,B,CStep-3BIG AStep-4IF B BIG THENBIG BENDIFStep-5IF C BIG THENBIG CENDIFStep-6Write BIGStep-7Stop16CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find Even number between 1 to 50AlgorithmStep-1 StartStep-2I 1Step-3IF (I 50) THENGO TO Step-7ENDIFStep-4IF ( (I % 2) 0) THENDisplay IENDIFStep-5I I 1Step-6GO TO Step--3Step-7 StopAlgorithm & Flowchart to find Odd numbers between 1 to n where n is apositive IntegerAlgorithmStep-1 StartStep-2 Input Value of NStep-3I 1Step-4IF (I N) THENGO TO Step-8ENDIFStep-5IF ( (I % 2) 1) THENDisplay IENDIFStep-6I I 1Step-7GO TO Step-4Step-8Stop17CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find sum of series 1 2 3 . NAlgorithmStep-1 StartStep-2 Input Value of NStep-3I 1, SUM 0Step-4IF (I N) THENGO TO Step-8ENDIFStep-5SUM SUM IStep-6I I 1Step-7Go to step-4Step-8Display value of SUMStep-9StopAlgorithm & Flowchart to find sum of series 1 3 5 . N, Where N is positiveodd IntegerAlgorithmAlgorithmStep-1 StartStep-2 Input Value of NStep-3I 1, SUM 0Step-4IF (I N) THENGO TO step 8ENDIFStep-5SUM SUM IStep-6I I 2Step-7Go to step-4Step-8Display value of SUMStep-9 Stop18CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find sum of series 1 – X X2 –X3 .XNAlgorithmStep-1 StartStep-2Input Value of N, XStep-3I 1, SUM 1, TERM 1Step-4IF (I N) THENGO TO Step-9ENDIFStep-5TERM - TERM * XStep-6SUM SUM TERMStep-7I I 1Step-8Go to step-4Step-9Display value of SUMStep-10 StopAlgorithm & Flowchart to print multiplication Table of a numberAlgorithmStep-1 StartStep-2 Input Value of NUMStep-3I 1Step-4IF (I 10) THENGO TO Step 9ENDIFStep-5PROD NUM * IStep-6WRITE I “x” NUM “ ” PRODStep-7I I 1Step-8Go to step-4Step-9Stop19CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to generate first n Fibonacci terms 0,1,1,2,3,5 n (n 2)AlgorithmStep-1 StartStep-2 Input Value of NStep-3A 0, B 1, COUNT 2Step-4WRITE A, BStep-5IF (COUNT N) then go to step 12Step-6NEXT A BStep-7WRITE NEXTStep-8A BStep-9B NEXTStep-10COUNT COUNT 1Step-11Go to step-4Step-12Stop20CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find sum and average of given series of numbersAlgorithmStep-1 StartStep-2COUNT 0Step-3SUM 0Step-4Input NUMStep-5SUM SUM NUMStep-6COUNT COUNT 1Step-7IF More Number in Series then(next number in series)GOTO Step-4ENDIFStep-8AVERGAE SUM / COUNTStep-9WRITE SUM, AVERAGEStep-10 Stop21CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find Roots of Quadratic Equations AX2 BX C 0AlgorithmStep-1 StartStep-2 Input A,B,CStep-3 DISC B2 – 4 A * CStep-4IF (DISC 0) THENWrite Roots are ImaginaryStopENDIFStep-5 IF (DISC 0) THENWrite Roots are Real and EqualX1 - B/(2*A)Write Roots are X1,X1StopENDIFStep-6 IF (DISC 0)Write Roots are Real and UnequalX1 (- B SQRT(DISC)) / (2*A)X2 (- B SQRT(DISC)) / (2*A)Write Roots are X1,X2StopENDIF22CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find if a number is prime or notAlgorithmStep-1 StartStep-2Input NUMStep-3R SQRT(NUM)Step-4I 2Step-5IF ( I R) THENWrite NUM is Prime NumberStopENDIFStep 6 IF ( NUM % I 0) THENWrite NUM is Not PrimeStopENDIFStep-7I I 1Step-8Go to Step-523CIC-UHF

Algorithm & Flowchart Manual.Algorithm & Flowchart to find GCD and LCM of two numbersAlgorithmStep-1 StartStep-2Read two number A, BStep-3IF (A B) THENN AD BELSEN BD AENDIFStep-4r N/DStep-5WHILE (r ! 0)DON DD rr N%DDONEStep-6gcd dStep-7lcm (a*b)/gcdStep-8Display gcd, lcmStep-9 Stop24CIC-UHF

Algorithm & Flowchart Manual Algorithm & Flowchart to find Factorial of number n ( n! 1x2x3x n)AlgorithmStep-1 StartStep-2Read number NStep-3 FACT 1 CTRL 1Step-4WHILE (CTRL N)DOFACT FACT*ICTRL CTRL 1DONEStep-5Display FACTStep-6 StopAlgorithm & Flowchart to find all the divisor of a numberAlgorithmStep-1 StartStep-2Read number NStep-3D 1Step-4WHILE (D N)DOIF ( N % D 0) THENPRINT DENDIFD D 1DONEStep-5 Stop25CIC-UHF

Algorithm & Flowchart Manual 4 CIC-UHF HOW TO WRITE ALGORITHMS Step 1 Define your algorithms input: Many algorithms take in data to be processed, e.g. to calculate the area of rectangle input may be the rectangle height and rectangle width.

Related Documents:

20. Write an algorithm and flowchart to find the given no is positive or not. 21. Write an algorithm and flowchart to swap the two nos. 22. Write an algorithm and flowchart to convert temperature in Celsius 23. Write an algorithm and flowchart take digit from user and display 24. Write an algorithm and flowchart enter year from user and check. 25.

Flowchart di bedakan menjadi 5 jenis flowchart, antara lain system flowchart, document flowchart, schematic flowchart, program flowchart, . menggunakan symbol-simbol bagan alir sistem, juga menggunakan gambar-gambar computer dan peralatan lainnya yang digunakan. Maksud penggunaa gambar-gambar ini adalah untuk memudahkan .

Bruksanvisning för bilstereo . Bruksanvisning for bilstereo . Instrukcja obsługi samochodowego odtwarzacza stereo . Operating Instructions for Car Stereo . 610-104 . SV . Bruksanvisning i original

Keep in mind that a flowchart may not need to include all the possible symbols. For example, the wait symbol ( ) may not be needed if the flowchart is not related to waiting times. Improving the layout of a flowchart Create a complex flowchart Analyzing the Detailed Flowchart to Identify Problem Areas

OA flowchart is the graphical or pictorial representation of an algorithm with the help of different symbols, shapes and arrows in order to demonstrate a process or a program. With algorithms, we can easily understand a program. The main purpose of a flowchart is to analyze different processes. Several standard graphics are applied in a flowchart:

10 tips och tricks för att lyckas med ert sap-projekt 20 SAPSANYTT 2/2015 De flesta projektledare känner säkert till Cobb’s paradox. Martin Cobb verkade som CIO för sekretariatet för Treasury Board of Canada 1995 då han ställde frågan

service i Norge och Finland drivs inom ramen för ett enskilt företag (NRK. 1 och Yleisradio), fin ns det i Sverige tre: Ett för tv (Sveriges Television , SVT ), ett för radio (Sveriges Radio , SR ) och ett för utbildnings program (Sveriges Utbildningsradio, UR, vilket till följd av sin begränsade storlek inte återfinns bland de 25 största

Hotell För hotell anges de tre klasserna A/B, C och D. Det betyder att den "normala" standarden C är acceptabel men att motiven för en högre standard är starka. Ljudklass C motsvarar de tidigare normkraven för hotell, ljudklass A/B motsvarar kraven för moderna hotell med hög standard och ljudklass D kan användas vid