1. Algorithm:
An algorithm is a well defined list of steps for solving
a particular problem.
The criteria of an algorithm are:
1. An algorithm takes zero or more input.
2. It produces at least one output. Sum := A + B
3. Each instruction must be clear.
4. If we trace out the instructions of an algorithm, then for
all cases, the algorithm terminates after a finite number
of steps.
5. Each instruction must be very basic so that it can be
carried out.
Read: A, B
add 6 or 7 to x
2. Write an algorithm to add two integer number
This algorithm takes two number as input and find the
summation of those numbers as output. Suppose the
two numbers A , B and sum is used for carrying out
the summation of these two numbers.
Step 1. Start
Step 2.Read : A, B
Step 3. Sum := A + B
Step 4. Write : sum
Step 5. Exit
Y=A+B; Y=10+11; Y=21
3. Write an algorithm that is used to convert the given
Fahrenheit temperature to Centigrade temperature.
This algorithm takes temperature in Fahrenheit (F) as
input and convert it to centigrade(C) as output.
Step 1. Start
Step 2. Read: F(Temperature in Fahrenheit)
Step 3.
Step 4. Write: C(Temperature in Centigrade)
Step 5. Exit
9
32)5(FC โ=
9
32)5(F:C โ=
4. Write an algorithm that will take three number
as input and find average of those number.
Step 1. Start
Step 2. Read: A, B, C
Step 3. Sum := A + B + C
Step 4. Ave:= Sum/3
Step 5. Write: Ave
Step 6. Exit
5. Write an algorithm to check if a given number is
Even or Odd. (4%2=0, 7%2=1, 8%2=0, 11%2=1)
This algorithm takes one number as input and find if the
number is even or odd. Here Let X = Given Number
Step 1. Start
Step 2. Read: X
Step 3. Y := X%2
Step 4. If Y := 0, Then
Write: Even Number
else
Write: Odd Number
Step 5. Exit
6. Write an algorithm to solve the following conditions:
1. Pay tax 150 if amount>=11500
2. Pay tax 100 if amount>=8000
3. Otherwise tax=0
In this algorithm we take amount as input and find payable tax as output.
Step 1. Start
Step 2. Read: amount
Step 3. If amount>=11500, then
Tax :=150
else if amount>=8000, then
Tax := 100
else
Tax := 0
Step 4. Write: Tax
Step 5. Exit
7. Suppose you will get Commission on the basis of your sell. The Criteria for getting
commission is given below:
1. 7% of total sell if Selling amount greater then or equal to 200000.
2. 5% of total sell if Selling amount greater then or equal to 150000.
3. 2% of total sell if Selling amount greater then or equal to 100000.
4. 1% Otherwise.
Step 1. Start
Step 2.Read: amount
Step 3. If amount>=200000, then
Commission :=amount * 7%
else if amount>=150000, then
Commission :=amount * 5%
else if amount>=100000, then
Commission :=amount * 2%
else
Commission :=amount * 1%
Step 4. Write: Commission
8. write an algorithm that will used to compute the following
after reading a value of X
1. Y=(X2
+ 2X โ1)/5 If X<0
2. Y= X โ 3 If X=0
3. Y= X โ 14 If X>0
Step 1. Start
Step 2. Read: X
Step 3. If X<0, then
Y:=(X2
+ 2X โ1)/5
else if X=0, then
Y:= X - 3
else
Y:= X โ 14
Step 4. Write: Y
Step 5. Exit
9. Write an algorithm to solve the following equation:
1+2+3+4+5+โฆโฆโฆ.+N
Step 1. Start
Step 2. Read: N
Step 3. Set K := 1, Sum:= 0
Step 4. Repeat Steps 5 and 6 while K<=N
Step 5. Sum := Sum + K
Step 6. Set K := K + 1
Step 7. Write: Sum
Step 8. Exit
10. Write an algorithm to solve the following equation:
12
+22
+32
+42
+52
+.......................+N2
Step 1. Start
Step 2. Read: N
Step 3. Set K := 1, Sum:= 0
Step 4. Repeat Steps 5 and 6 while K<=N
Step 5. Sum := Sum + (K*K)
Step 6. Set K := K + 1
Step 7. Write: Sum
Step 8. Exit
11. Write an algorithm to solve the following equation:
1+3+5+7+.......................+N
Step 1. Start
Step 2. Read: N
Step 3. Set K := 1, Sum:= 0
Step 4. Repeat Steps 5and 6 while K<=N
Step 5. Sum := Sum + K
Step 6. Set K := K + 2
Step 7. Write: Sum
Step 8. Exit
12. Write an algorithm to find the factorial of a given number.
1*2*3*4*5โฆ..*N=N!
Step 1. Start
Step 2. Read: N
Step 3. Set K := 1, Fact:= 1
Step 4. Repeat Steps 5 and 6 while K<=N
Step 5. Fact:= Fact * K
Step 6. Set K := K + 1
Step 7. Write: Fact
Step 8. Exit
13. Write an algorithm to calculate the following equation
y=a2
+2ab+b2
Step 1. Start
Step 2. Read: a, b
Step 3. y := a2
+2ab+b2
Step 4. Write: y
Step 5. Exit
14. Write an algorithm to find result using the following
conditions:
Conditions Result
Marks>=80 A+
Marks>=75 A
Marks>=70 B+
Marks>=65 B
Marks>=60 D
F Otherwise
15. Step 1. Start
Step 2. Read: Marks
Step 3. If Marks>=80, then
result:=โA+โ
else if Marks>=75, then
result:=โA-โ
else if Marks>=70, then
result:=โB+โ
else if Marks>=65, then
result:=โBโ
else if Marks>=60, then
result:=โDโ
else result:=โFโ
Step 4. Write: result
Step 5. Exit