Write an algorithm to calculate and print the total

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: We saw above that planning a program basically involves defining its logic (the correct sequence of instructions needed to solve the problem at hand). The term algorithm is often used to refer to the logic of a program. It is a step-by-step description of how to arrive at the solution of the given problem. It may be formally defined as a sequence of instructions designed in such a way that if the instructions z executed in the specified sequence, the desired results will be obtained. The instructions, however, should precise and unambiguous and the result should be obtained after a finite number of executional steps. The latter condition actually states that an algorithm must terminate and should not repeat one or more instructions infinitely. Hence, in order to qualify as an algorithm, a sequence of instructions must possess the following characteristics: 1. Each and every instruction should be precise and unambiguous. 2. Each instruction should be such that it can be performed in a finite time. 3. One or more instructions should not be repeated infinitely. This ensures that the algorithm w ultimately terminate. 4. After performing the instructions, that is after the algorithm terminates, the desired results must obtained. Sample Algorithms To gain insight into algorithms, let us consider some simple examples. Example 11.1. There are 50 students in a class who appeared in their final examination. Their mark sheets have bi given to you. The division column of the mark sheet contains the division (FIRST, SECO> THIRD or FAIL) obtained by the student. Write an algorithm to calculate and print the total num of students who passed in FIRST division. Algorithm: Step 1: Initialize Total_First_Division and Total_Marksheets_Checked to zero. Step 2: Take the mark sheet of the next student. Step 3: Check the division column of the mark sheet to see if it is FIRST, if no, go to Step 5. Step 4: Add 1 to Total_First_Division. Step5: Add 1 to Total_Marksheets_checked. Step 6: Is Total_Marksheets_Checke...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online