Example of a very simple algorithm

Now that you understand the basic definition of an algorithm let’s take an example of a very simple algorithm. This example will help you understand how algorithms are written and what all things you should keep in mind while writing an algorithm.

Problem definition

Write an algorithm (steps) to add two numbers A and B and store the result in C. Print the value of C on the screen.

Let’s understand this problem first

The problem defined above is about a very simple algorithm to do the sum of two numbers. Humans are good at remembering data and performing operations on that data. But computers work in a slightly different manner. They use something called variables to remember the data. This problem talks about three data elements – 2 numbers which are to be added and the sum which we will get after the addition. So we will have to take total three variables to store these data elements.

Let’s write the algorithm

Step 1: Take two variables A and B to store two numbers
Step 2: Take a variable C to store the sum
Step 3: Read value of A and B
Step 4: Set C = A + B
Step 5: Print the value of C

You can see how simple it is to write an algorithm. All you have to do is convert your thoughts into an algorithm by writing the steps in simple English and give them proper step numbers. In the example we just discussed there were no conditions and no repeating statements. But in the real world problems you will find many conditions and repeating statements. In the next tutorials we will give you examples on how to write algorithms with conditional statements.

Quick Links



Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..


Login to Open ESchool OR Create your account    Login   SignUp