Algorithms
Example - 1: addition of two numbers
1) Take 2 numbers a,b
2) Add the two numbers a,b i.e., c=a+b
3) display sum or c value
Example - 2: greatest in two numbers
1) take 2 numbers a,b
2) compare a and b
if a>b go to step 3 else go to step 4
3) display a as greatest
4) display b as greatest
example 3: Even or odd
1) Take one number as input
2) Divide the given number by 2 and check the remainder
3) If remainder==0 display as even else display as odd
**
/ - quotient
% - remainder
**
Step 1 : Start
Step 2 : Read number "n"
Step 3 : rem = n%2 (Initialise remainder as rem)
Step 4 : If rem = 0, print even
Step 5 : Else print odd
Step 6 : End
example 4: Adding two numbers
Step 1 : Start
Step 2 : Read numbers "a","b"
Step 3 : c = a + b
Step 4 : Print "c"
Step 5 : End
example 5: Adding two numbers and print sum only if it is greater than 100
Step 1 : Start
Step 2 : Read numbers "a","b"
Step 3 : c = a + b
Step 4 : If c>100,print "c"
Step 5 : End
example 6 : Adding two numbers and print sum only if it is greater than 100 else
ask user to input again
Step 1 : Start
Step 2 : Read numbers "a","b"
Step 3 : c = a + b
Step 4 : If c>100,print "c"
Step 5 : Else print "Enter input again"
Step 6 : End
example 7 : Adding two numbers and print sum only if input is even
Step 1 : Start
Step 2 : Read numbers "a", "b"
Step 3 : c = a + b
Step 4 : rem1 = a%2, rem2 = b%2
Step 5 : if rem1,rem2 = 0, print "c"
Step 6 : End
example 8 : Take 5 subject marks, print grade as A+ if percentage is >=85
A if " " between 70 and 85
B if " " between 60 and 70
Step 1 : Start
Step 2 : A,B,C,D,E are the 5 subjects
Step 3 : Read numbers 'A','B','C','D','E'
Step 3 : Total = A + B + C + D + E
Step 4 : Percentage = Total/5
Step 5 : if Percentage>=85 go to step 6 else go to step 7
Step 6 : Display A+
Step 7 : if 70<=Percentage<85 go to step 8 else go to step 9
Step 8 : display A
Step 9 : if 60<=Percentage<70 go to step 10
Step 10 : Display B
Step 11 : End
example 9 : Generate electricity bill on following constraints
if no of units consumed is 0--200--Rs 500
200--500 -- 500 + each unit extra*2rs
500--700 -- 500 + each unit extra*4rs
Step 1 : Start
Step 2 : no of units consumed is "u"
Step 3 : if u>=0 and u<=200 go to step 4, else go to step 5
Step 4 : display electricity bill is Rs 500
Step 5 : if u>=200 and u<=500 go to step 6 else go to step 7
Step 6 : display electricity bill is Rs 500+((u-200)*2)
Step 7 : if u>=500 and u<=700 go to step 8
Step 8 : display electricity bill is 500+((u-200)*4)
Step 9 : End
example 10 : Tax deduction
version 1 : problem description
Given gross salary of an employee. Find out the tax deduction based on the
following constraints :
if gross salary < 5lpa zero tax
>5 and <10 lpa 10%gross
>10lpa < 15lpa 15%gross
Step 1 : Start
Step 2 : gross salary of an employee is "s"
Step 3 : if s<5 go to step 4 else go to step 5
Step 4 : display tax deduction=0
Step 5 : if s>5 and s<10 go to step 7 else go to step 8
Step 6 : tax deduction = s*(10/100)
Step 7 : display tax deduction
Step 8 : if s>10 and s<15 go to step 9
Step 9 : tax deduction = s*(15/100)
Step 10 :display tax deduction
Step 11 : End
example 11 :Given two nos, sort the two nos
Step 1: Start
Step 2: Take two numbers A,B
Step 3: If A>B go to step 4 else go to step 5
Step 4: Display A,B
Step 5: Display B,A
Step 6: End
example 12 : greatest of 3 nos
Step 1 : Start
Step 2 : take 3 number a,b,c
Step 3 : if a>b go to step 6 else go to step 5
Step 4 : if a>c go to step 8 else ngo to step 7
Step 5 : if b>c go to step 8 else go to step7
Step 6 : display a is greatest
Step 7 : display c is greatest
Step 8 : display b is greatest