Sunday, February 22, 2015

Algorithms

There are four types of algorithms:  Simple, Conditional, Loops and Arrays

Simple Algorithms - basic calculations
Conditional Algorithms - selection statements

Algorithms are series of instructions that rigorously defines the solution to a problem.

The attributes of an algorithm are:

  1. Must be precise
  2. Must be ambiguous
  3. Must be finite
  4. Must be done in a logical order
Example of given problem:
Write an algorithm that prompts the user to enter two grades, and shows the average of the two grades.

Indicators that it is a simple algorithm:  basic calculation of entering data, performing calculation, and outputting results.

Solution:
Print "Enter a grade"
Input grade1
Print "Enter another grade"
Input grade2
Let total = grade1 + grade2
Let avg = total / 2
Print "The average of two grades is", avg
Input key

No comments:

Post a Comment