Unit I Algorithm
Unit I Algorithm
UNIT I
INTRODUCTION TO COMPUTERS AND ALGORITHMS
ALGORITHM
Need of Algorithm
How to write Algorithm
Examples
To write a correct program, a programmer must write each and every instruction in
the correct sequence
Logic (instruction sequence) of a program can be very complex
Hence, programs must be planned before they are written to ensure program
instructions are:
Appropriate for the problem
In the correct sequence
Step 1: Start
Step 2: I=0
Step 3: Sum=0
Step 4:Sum=Sum+I
Step 5: if I =15 then
Goto 6
else I=I+1
Goto 4
endif
Step 6: print Sum
Step 7: stop
Step 1: Start
Step 2: Input n
Step 3: I=1
Step 4: X=1
Step 5: X=X*I
Step 6: if I = n then
Goto 7
else I=I+1
Goto 5
endif
Step 7: print X
Step 8: stop
Step 3: Check the division column of the mark sheet to see if it is FIRST, if yes go
to step 4 , if no, go to Step 5.
7: Print Total_First_Division.
Step 8: Stop.
Program Name: B.Tech (CSE)
Example 5
There are 100 employees in an organization. The organization wants to distribute annual bonus
to the employees based on their performance. The performance of the employees is recorded in
their annual appraisal forms.
Every employee’s appraisal form contains his/her basic salary and the grade for his/her
performance during the year. The grade is of three categories – ‘A’ for outstanding performance,
‘B’ for good performance, and ‘C’ for average performance.
It has been decided that the bonus of an employee will be 100% of the basic salary for
outstanding performance, 70% of the basic salary for good performance, 40% of the basic
salary for average performance, and zero for all other cases.
Write an algorithm to calculate and print the total bonus amount to be distributed by the
organization.