Algorithms vca ii year.docx

Embed Size (px)

Citation preview

Algorithms

An algorithm is any well defined set of instructions that takes some value, or set of values as Input, and produces some value, or set of values as output. An algorithm is thus a sequence of computational steps that transform the input into the output.We can also say that an algorithm is a mechanism for solving a given problem. The statement of the problem specifies the desired input/output relationship.ExampleWrite an algorithm to find area of a rectangle.Step 1: StartStep 2: Take length and breadth and store them as L and B?Step 3: Multiply by L and B and store it in areaStep 4: Print areaStep 5: Stop

Write an algorithm to check whether he is eligible to vote? (More than or equal to 18 years old).Step 1: StartStep 2: Take age and store it in ageStep 3: Check age value, if age >= 18 then go to step 4 else step 5Step 4: Print Eligible to vote and go to step 6Step 5: Print Not eligible to voteStep 6: Stop

Write an algorithm to arrange values in ascending orderStep1: StartStep 2: Take input of 10 values and store in AStep 3: i=0Step4: Check I, if I