Sie sind auf Seite 1von 21

Fifty students in a class appeared in their final examination.

the division column of their marksheet contains the division(First,Second,Third or Fail) obtained by them.If their marksheet re available with you,Write an algorithm to calculate and print the total no of students who passed in 1st division.

. Initialize Total_first_division and Total_marksheet to zero.


Take the marksheet of nxt student. Check the division column of the marksheet to see if it is first.if no,goto step 5. Add 1 to total_first_division. Is total_marksheet_checked=50?if no,goto step 2. Print total_first_division. Stop

Representation of Algorithms
Tools used to document and represent program logic are: Programs Flowcharts Pseudocodes.

Flowchart
Pictorial representation of algorithm A program planning tool for visually organising sequence of steps Boxes of different shapes denote different types of instructions Instructions are written within the boxes Solid lines with arrow marks connect these boxes to indicate the flow of operation

Details
TerminatorIndicates beginning , end , pause in programs logic flow Input/output---- Instructions to I/O data from any type of I/O devices Process--- Represents arithmetic and data movement instructions Decision----A point at which a branch to one of 2 or more alternative points is possible

Contd
Connectors---A pair of identically labeled connector symbol indicate continued flow Flow Lines---Indicate flow of operation i.e sequence in which instructions are executed

Advantages
Proper Program Documentation Efficient Coding Systematic Testing and Debugging

limitations
Time consuming Modifications require completely new flowchart No standards to determine the details to be included

Example
flowchart for a program that reads two numbers and displays the numbers read in decreasing order

Example

Pseudo Code
Phrases written in ordinary natural language that computer cant understand Also known as Program Design Language It does not have any syntax rules for formulating instrctions

Pseudocodes for Basic Logic Structures


Sequence Logic Selection Logic Iteration/Looping Logic

Sequence Logic
Performing instructions one after the other in sequence

Contd
Flowchart Pseudo code Read NAME, BALANCE, RATE Compute INTEREST as BALANCE x RATE Write (Display) NAME and INTEREST

Selection/Decision Logic
To select proper path out of 2 or more alternative paths in program logic

Iteration Logic
When 1 or more instructions may be executed several times depending on some condition

Types of loops

Contd
Most programs involve repeating a series of instructions over and over until some event occurs. For example, if we wish to read ten numbers and compute the average, we need a loop to count the number of numbers we have read. Count loops are loops where the program must count the number of times operations are completed.

Pseudo code for pretest and post test loops


set average to zero set count to zero set total to zero read number while ( not end-of-data ) increment count by 1 total = total + number read number if ( count > 0 ) then average = total / count display average set average to zero set count to zero set total to zero do read a number increment count by 1 total = total + number while ( not end-of-data ) if ( count > 0 ) then average = total / count display average

Das könnte Ihnen auch gefallen