0% found this document useful (0 votes)
2 views48 pages

Algorithms and Flowcharts

Uploaded by

hdgdjehss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views48 pages

Algorithms and Flowcharts

Uploaded by

hdgdjehss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Algorithm in Programming

In programming, algorithm are the set of well-defined instruction in sequence to solve a program. An
algorithm should always have a clear stopping point.

Qualities of a good algorithm

1. Inputs and outputs should be defined precisely.


2. Each steps in algorithm should be clear and unambiguous.
3. Algorithm should be most effective among many different ways to solve a problem.
4. An algorithm shouldn't have computer code. Instead, the algorithm should be written in such a
way that, it can be used in similar programming languages.

Algorithm is not the computer code. Algorithm are just the instructions which gives clear idea to your
idea to write the computer code

Algorithms for the best practice


Write an algorithm to find the area of a Circle using radius r ___________________________________________ 3
Write an algorithm to read two numbers and find their sum ___________________________________________ 3
Write an algorithm to convert temperature Fahrenheit to Celsius _______________________________________ 4
Write an algorithm in pseudocode that finds the average of two numbers ________________________________ 5
Algorithm and flowchart is for swapping of given two numbers without using third number. _________________ 6
Write an algorithm to find the largest number from given two numbers __________________________________ 7
Write an algorithm to check voter eligibility criteria __________________________________________________ 8
Write an algorithm to declare Pass/Fail based on his/her subject marks __________________________________ 8
Write an algorithm to check leap year _____________________________________________________________ 9
Write an algorithm to print 1 to 100 natural numbers and Total Sum ___________________________________ 10
Write an algorithm to print 1 to 100 even numbers _________________________________________________ 11
Write an algorithm to find the factorial of a number entered by user ___________________________________ 12
Write an algorithm to find the factors of a number entered by user ____________________________________ 13
Write algorithm to find the result of equation: 𝑓𝑥 = −𝑥 , 𝑥 < 0 𝑥, 𝑥 > 0 _____________________________ 14
Design an algorithm to print odd numbers and their sum until given range of value (n)_____________________ 15
Design an algorithm to evaluate the following equation from given nth value ____________________________ 16
Equation: - S = ½ + ¼ + … +1/n ___________________________________________________________________ 16
Write an algorithm to find average age of a group of 10 players? ______________________________________ 17
Jairam goes to market for buying some fruits and vegetables. He is having a currency of Rs 500 with him for
marketing. From a shop he purchases 2.0 kg Apple priced Rs. 50.0 per kg, 1.5 kg Mango priced Rs.35.0 per kg, 2.5
kg Potato priced Rs.10.0 per kg, and 1.0 kg Tomato priced Rs.15 per kg. He gives the currency of Rs. 500 to the
shopkeeper. Find out the amount shopkeeper will return to jairam. and also tell the total item purchased. ____ 19
Write an algorithm to find the largest among three different numbers entered by user. ____________________ 22
Write an algorithm to find all roots of a quadratic equation ax2+bx+c=0. ________________________________ 22
Write an algorithm to check whether a number entered by user is prime or not. __________________________ 24
Write an algorithm to find the Fibonacci series till term≤1000. ________________________________________ 25
Design an algorithm to convert a decimal number into binary format? __________________________________ 26
Write an Algorithm to print a number in reverse and Check whether a Number is Palindrome or Not _________ 28
Write an Algorithm to Print Sum of Digits from User Input ____________________________________________ 29
Write an Algorithm to check a number is perfect square or perfect cube ________________________________ 31
Write an Algorithm to check whether a given number is perfect number or not __________________________ 33
Write an Algorithm to check whether a number is negative, positive or zero._____________________________ 35
Write an Algorithm to check whether a number is divisible by 5 and 11 or not. ___________________________ 36
Write an Algorithm to check whether a number is even or odd. _______________________________________ 37
Write an Algorithm to input week number and print week day. ________________________________________ 37
Write an Algorithm to input month number and print number of days in that month. ______________________ 39
Write an Algorithm to input angles of a triangle and check whether triangle is valid or not. _________________ 39
Write an Algorithm to input all sides of a triangle and check whether triangle is valid or not. ________________ 40
Write an Algorithm to check whether the triangle is equilateral, isosceles or scalene triangle. _______________ 40
Write an Algorithm to calculate profit or loss. ______________________________________________________ 41
Write an Algorithm to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer.
Calculate percentage and grade according to following: ______________________________________________ 42
Write an Algorithm to input basic salary of an employee and calculate its Gross salary according to following:__ 44
Write an Algorithm to input electricity unit charges and calculate total electricity bill according to the given
condition: ___________________________________________________________________________________ 46
Write an algorithm to find the area of a Circle using radius r
Step1: Start
Step2: Read\input the Radius r of the Circle
Step3: set Area  PI*r*r // calculation of area
Step4: Print Area
Step5: End

Write an algorithm to read two numbers and find their sum


Step1: Start
Step2: Input First Number 1
Step3: Input Second Number 2
Step4: Set Sum  Number 1 + Number 2
Step5: Print Sum
Step6: End
Write an algorithm to convert temperature Fahrenheit to Celsius
Step1: Start
Step2: Read Temperature in Fahrenheit F
Step3: Set C  5/9*(F-32)
Step4: Print “Temperature in Celsius: “+C
Step5: End
Write an algorithm in pseudocode that finds the average of two numbers
Step1: Start
Step2: Declare Variables num1, num2, avg, sum
Step3: Read | input values num1, num2
Step4: sum  num1 + num2
Step5: avg sum/2
Step6: Display “The Average of two numbers”+Avg
Step6: End
Algorithm and flowchart is for swapping of given two numbers without using
third number.
Step 1: Start
Step 2: Declare Variables num1, num2
Step 3: Display “Please Enter Two Numbers “
Step 4: Read Values num1, num2
Step 5: Set num2  num1+num2
Step 6: Set num1  num2- num1
Step 7: Set num2  num2-num1
Step 8: Display “After Swapping given number are”+ num1, num2
Step 8: End
Write an algorithm to find the largest number from given two numbers
Step1: Start
Step2: Declare variables num1, num2 and Largest_Num
Step3: Read | input values num1, num2
Step4: if num1 greater than num2
4.1 set Largest_Num  num1
else
4.2 set Largest_Num  num2
Step 6: endif
Step7: Print | Display Largest_Num
Step18: End
Write an algorithm to check voter eligibility criteria
Step1: Start
Step2: Declare variable age
Step3: Read | input value age
Step4: if age greater than or equals to 18
4.1 display “you can vote”
else
4.2 display “you are not eligible for voting”
Step5:endif
Step6: End

Write an algorithm to declare Pass/Fail based on his/her subject marks


Step1: Start
Step2: Declare variable sub_Mark
Step3: Read | input value sub_Mark
Step4: if sub_Mark greater than or equals to 50
4.1 display “Passed”
else
4.2 display “Fail”
Step5:endif
Step6: End

Write an algorithm to check leap year


Step1: Start
Step2: Declare variable year
Step3: Read | input value year
Step4: if year %4 is equals to 0 and year %100 is not equals to 0
Or year % 400 is equals to 0
4.1 display “Leap Year”
else
4.2 display “Common Year”
Step5:endif
Step6: End
Write an algorithm to print 1 to 100 natural numbers and Total Sum
Step 1: Start
Step 2: Declare variables n, i, Total _Sum
Step 3: Read value of n
Step 4: Initialize variables
4.1 Set i←1
4.2 Set Total_Sum  0
Step 5: Repeat the steps until i greater than n
5.1: display i
5.2: Set Total_Sum  Total_Sum+i
5.3: increment i // (i.e. i=i+1)
Step 6: Display “1 to 100 Natural Numbers Sum:”+Total_Sum
Step 7: End
Write an algorithm to print 1 to 100 even numbers
Step 1: Start
Step 2: Declare variables n, even.
Step3: input | read value of n
Step4: Set even2
Step5: while even greater than n
5.1: Display even
5.2 Set even  even+2
Step6: Endwhile
Step 7: End
Write an algorithm to find the factorial of a number entered by user
Step 1: Start
Step 2: Declare variables n, factorial, i
Step3: Read Value n.
Step4: Initialize variables
4.1 Set factorial←1
4.2 Set i←1
Step 5: Repeat the steps until i greater than n
5.1 set factorial  factorial*i
5.2 set increment i
Step 6: Display “The factorial of Given Number:”+factorial
Step 7: End

Write an algorithm to find the factors of a number entered by user


Step 1: Start
Step 2: Declare variables fct, i
Step3: Read Value fct.
Step4: Initialize variables
4.1 Set i←1
Step5: Repeat the steps until i greater than fct
5.1 if fct modulo i equals to 0 // (remainder of fct/i)
5.1.1 Display i
5.2 Endif
5.3 Set increment i
Step 6: End

−𝑥 , 𝑥 < 0
Write algorithm to find the result of equation: 𝑓(𝑥) = {
𝑥, 𝑥 > 0
Step 1: Start
Step 2: Declare variables x, f
Step3: Read Value x
Step4: Set f 0
Step5: if x less than 0
5.1 Set f  -x
else
5.2 Set f ← x
Step 6: Endif
Step 7: Display “To Display f(x) Value “+f
Step 8: End

Design an algorithm to print odd numbers and their sum until given range of
value (n)
Step 1: Start
Step 2: Declare variables n, i, sum
Step3: input | read value of n
Step4: Initialize variables
4.1 Set i1
4.2 Set sum0
Step5: while i greater than n
5.1 Display i
5.2 Set Sum  sum+i
5.2 Set ii+2
Step6: End while
Step7: Display “Sum of odd Numbers “+Sum
Step 8: End

Design an algorithm to evaluate the following equation from given nth value
Equation: - S = ½ + ¼ + … +1/n
Step 1: Start
Step 2: Declare Variables n, i,S
Step 3: Read Values n
Step 4: Initialize variables
4.1 Set i  2
4.2 Set S  0
Step5: Repeat the Steps until i greater than n
5.1 Set S  S + (1/i)
5.2 Set i  i+2
Step6: Display “Display the given Equation Sum”+S
Step7: End

Write an algorithm to find average age of a group of 10 players?


Step 1: Start
Step 2: Declare Variables n, i, Sum, Age_Avg, P_Age
Step 3: Read Values n
Step 4: Initialize variables
4.1 Set i  1
4.2 Set Sum  0
Step5: Repeat the Steps until i greater than n
5.1 Read Player P_Age
5.1 Set Sum  Sum +P_ Age
5.2 Set i  i+1
Step6: Set Age_Avg  Sum/n

Step7: Display “average age of a group of 10 players “+Age_Avg


Step8: End
Jairam goes to market for buying some fruits and vegetables. He is having a currency of
Rs 500 with him for marketing. From a shop he purchases 2.0 kg Apple priced Rs. 50.0
per kg, 1.5 kg Mango priced Rs.35.0 per kg, 2.5 kg Potato priced Rs.10.0 per kg, and 1.0
kg Tomato priced Rs.15 per kg. He gives the currency of Rs. 500 to the shopkeeper. Find
out the amount shopkeeper will return to jairam. and also tell the total item purchased.

2kg apples 2*50=100


1.5kg mango 1.5*35=52.50
2.5kg potato 2.5*10=25
1kg tomato 1*15=15
Step 1: Start
Step 2: Declare Variables Tfrt_Vgtbl, Uprice, TCost, TAvl_Mny, Blnc, NItms
Step 3: Initialize variables
3.1 Set TAvl_Mny  500
3.2 Set Blnc  0
3.3 Set TCost  0
3.4 Set Stop  0
3.5 Set NItms  0
Step 4: Repeat the Steps until Stop Equals to 99 //
4.1 Read Values Tfrt_Vgtbl, Uprice
4.2 Set TCost  TCost+NUnts*Uprice
4.3 Set Increment NItms
4.4 Read “Do you want Exit Enter 99 ”
Step 5: Set Blnce  TAvl_Mny - TCost
Step7: Display “Number Items are “+NItms +”\nTotal Spending
Money:”+TCost+”\nRemaining Balance Amount:”+Blnc
Step 8: End
Write an algorithm to find the largest among three different numbers entered by user.
Step 1: Start
Step 2: Declare variables a, b and c.
Step 3: Read variables a, b and c.
Step 4: If a greater than b
4.1 If a greater than c
4.1.1 Display a is the largest number.
else
4.1.2 Display c is the largest number.
4.2 endif
else
4.3 If b greater than c
4.3.1 Display b is the largest number.
else
4.3.2 Display c is the greatest number.
4.4 endif
Step 5: Endif
Step 6: Stop

Write an algorithm to find all roots of a quadratic equation ax2+bx+c=0.


Step 1: Start
Step 2: Declare variables a, b, c, D, r1, r2, rp and ip;
Step 3: Read Values a, b, c
Step 4: Calculate discriminant
4.1 Set D ← b2-4ac
Step 5: If D≥0
5.1 Set r1 ← (-b+√D)/2a
5.2 Set r2 ← (-b-√D)/2a
5.3 Display r1 and r2 as roots.
Else
5.4 Calculate real part and imaginary part
5.5 Set rp ← b/2a
5.6 Set ip ← √(-D)/2a
5.7 Display rp+j (ip) and rp-j (ip) as roots
Step 6: Endif
Step 7: End
Write an algorithm to check whether a number entered by user is prime or not.
Step 1: Start
Step 2: Declare variables n, i, count.
Step 3: Read n from user
Step 4: Initialize variables
4.1 Set count←1
4.2 Set i  2
Step 5: Repeat the steps until i less than (n/2)
5.1 If remainder of n module (%) i equals to 0
5.1.1 Set count←0
5.2 Endif
5.3 Set i←i+1
Step 6: If count equals to 0
6.1 Display n is not prime
else
6.2 Display n is prime
Step 7: Endif
Step 8: End
Write an algorithm to find the Fibonacci series till term≤100.
Step 1: Start
Step 2: Declare variables f1, f2, temp.
Step 3: Initialize variables
3.1 Set f1 ← 0
3.2 Set f2 ← 1
Step 4: Repeat the steps until f2 greater than 100
4.1: Display f2
4.2: Set temp←f2
5.2: Set f2 ← f2+f1
5.3: Set f1 ← temp
Step 6: Stop
Design an algorithm to convert a decimal number into binary format?
Step 1: Start
Step 2: Declare Variables num, decimal_num, remainder, base, binary, no_of1s
Step 3: Initialize variables
3.1 Set base  1
3.2 Set binary  0
3.3 Set no_of1s  0
Step 4: Display “Please Enter Decimal Number “
Step 5: Read Value decimal_num
Step 6: Set num  decimal_num
Step 7: While num less than or equals to 0
7.1 Set remainder  num module 2
7.2 Set binary  binary + remainder * base
7.3 Set num  floor (num /2)
7.4 Set base  base *10
Step 6: End while
Step 7: Display “Input number is”+ decimal_num
Step 8: Display “Its binary equivalent is: “+binary
Step 9: End
Write an Algorithm to print a number in reverse and Check whether a
Number is Palindrome or Not
a. Example if input number is 101, then output is 101 it is palindrome

b. Example if input number is 123, then output is 321 it is not palindrome

Step 1: Start
Step 2: Declare Variables num, temp, remainder, reverse
Step 3: Initialize variables
3.1 Set reverse  0
Step 4: Display “Please Enter Number “
Step 5: Read Value num
Step 6: Set temp  num
Step 7: While num less than or equals to 0
7.1 Set remainder  num module 10
7.2 Set reverse  reverse*10 + remainder
7.3 Set num  floor (num /10)
Step 8: End while
Step 9: Display “Input number is”+ temp
Step 10: Display “Reverse number is”+ reverse
Step 11: if reverse equals to temp
11.1 Display “The Given Number is Palindrome”
else
11.2 Display “The Given Number is not Palindrome”
Step 12: Endif
Step 13: End
Write an Algorithm to Print Sum of Digits from User Input
a. Example if input number is 123, then output is 6(1+2+3)

b. Example if input number is 101, then output is 2(1+0+1)

Step 1: Start
Step 2: Declare Variables num, remainder, sum
Step 3: Initialize variables
3.1 Set sum  0
Step 4: Display “Please Enter a Number “
Step 5: Read Value num
Step 6: While num less than or equals to 0
6.1 Set remainder  num module 10
6.2 Set sum  sum + remainder
6.3 Set num  floor (num /10)
Step 7: End while
Step 8: Display “Input number is”+ temp

Step 9: Display “Sum of Digits are”+ sum

Step 10: End


Write an Algorithm to check a number is perfect square or perfect cube
Step 1: Start
Step 2: Declare Variables num, count,i
Step 3: Initialize variables
3.1 Set count  0
3.2 Set i  1
Step 4: Display “Please Enter a Number “
Step 5: Read Value num
Step 6: While i greater than or equals to 0
6.1 if num equals to i * i
6.1.1 Set count  1
6.2 Endif
6.3 if num equals to i*i*i
6.3.1 Set count  2
6.4 Endif
6.5 Set i  i+1
Step 7: End while
Step 8: if count equals to 1
8.1 Display “Input number is”+ num +” it is Perfect Square”
else
8.2 if count equals to 2
8.2.1 Display “Input Number is “+num+”It is Perfect Cube”
else
8.2.2 Display “Input Number is “+num+”It is NotPerfect Square &
Cube”
8.3 Endif
Step 9:Endif
Step 10: End
Write an Algorithm to check whether a given number is perfect number or
not
Sum of factors and excluding given number then we call it as perfect number

Example: 6 number factors are 1, 2 and 3 and factors sum is 6 (1+2+3=6)

Example: 28 numbers factors are 1, 2, 4, 7 1nd 14 and factors sum is 28 (1+2+4+7+14)

Step 1: Start
Step 2: Declare Variables num, Perfect,i
Step 3: Initialize variables
3.1 Set Perfect  0
3.2 Set i  1
Step 4: Display “Please Enter a Number “
Step 5: Read Value num
Step 6: While i greater than or equals to num
6.1 if num module i equals to 0 // Remainder of num/ i
6.1.1 Set Perfect  Perfect + i
6.2 Endif
6.3 Set i  i+1
Step 7: End while
Step 8: if Perfect equals to num
8.1 Display “Input number is”+ num +” it is Perfect Number”
else
8.2. Display “Input Number is “+num+”It is Not Perfect Number”
8.3 Endif
Step 9:Endif
Step 10: End
Write an Algorithm to check whether a number is negative, positive or zero.
Step 1: Start
Step 2: Declare variable num
Step 3: Read variable num
Step 4: If num equals to 0
4.1 Display “The Given Number is Zero”.
else
4.2 if num Less than 0.
4.2.1 Display “The Given Number is Negative”.
else
4.2.2 Display “The Given Number is Positive “.
4.3 Endif
Step 5: Endif
Step 6: Stop

Write an Algorithm to check whether a number is divisible by 5 and 11 or not.


Step 1: Start
Step 2: Declare variable num, x, y
Step 3: Read variable num, x, y
Step 4: If num modulo x equals to 0 and num modulo y equals to 0
4.1 Display “Number is divisible by 5 and 11”.
else
4.2 Display “"Number is not divisible by 5 and 11”.
Step 5: Endif
Step 6: Stop
Program To Check That a Given Number Is Divisible By 11 Or Not, Under Condition That Sum Of Digits At Odd
Position Is Equal To, Sum Of Digits At Even Positions
Write an Algorithm to check whether a number is even or odd.
Step 1: Start
Step 2: Declare variable num
Step 3: Read variable num
Step 4: If num modulo 2 equals to 0
4.1 Display “Number is Even”.
else
4.2 Display “"Number is Odd”.
Step 5: Endif
Step 6: Stop

Write an Algorithm to input week number and print week day.


Step 1: Start
Step 2: Declare variable week_day
Step 3: Initialize Variables
3.1 Display “Enter Week Number (1-7)”
3.2 Read variable week_day
Step 4: If week_day equals to 1
4.1 Display “MONDAY”.
4.2 else if week_day equals to 2
4.2.1 Display “TUESDAY”
4.2.2 else if week_day equals to 3
4.2.2.1 Display “WEDNSDAY”
4.2.2.2 else if week_day equals to 4
4.2.2.2.1 Display “THURSDAY”
4.2.2.2.2 else if week_day equals to 5
4.2.2.2.2.1 Display “FRIDAY”
4.2.2.2.2.2 else if week_day equals to 6
4.2.2.2.2.2.1 Display “SATURDAY”
4.2.2.2.2.2.2 else if week_day equals to 7
4.2.2.2.2.2.2.1 Display “SATURDAY”
else
4.2.2.2.2.2.2.2 Display “Invalid Input!”
4.2.2.2.2.2.3 endif
4.2.2.2.2.3 endif
4.2.2.2.3 endif
4.2.2.3 endif
4.2.3 endif
4.3 endif
Step 5: Endif
Step 6: Stop
Write an Algorithm to input month number and print number of days in that
month.
Step 1: Start
Step 2: Declare variable Month
Step 3: Initialize Variables
3.1 Display “Enter Month Number (1-12)”
3.2 Read variable Month
/* Group all 31 days conditions together using logical or operator */
Step 4: If Month equals to 1 || Month equals to 3 || Month equals to 5 || Month
equals to 7 || Month equals to 8 || Month equals to 10 || Month equals to 12
4.1 Display “31 Days”
4.2 Else if Month equals to 2
4.2.1 Display “28 Days or 29 Days”
Else
4.2.2 Display “30 Days”
4.3 ednif
Step 5:Endif

Write an Algorithm to input angles of a triangle and check whether triangle is


valid or not.
Step 1: Start
Step 2: Declare variable a, b, c, sum
Step 3: Initialize Variables
3.1 Display “Enter three angles of triangle”
3.2 Read variable a, b,c
Step 4: Set sum  a+b+c
Step 5: If sum equals to 180
5.1 Display “Triangle is valid”
Else
5.2 Display “Triangle is not valid”
Step 5: Endif
Step 6: End

Write an Algorithm to input all sides of a triangle and check whether triangle
is valid or not.
Step 1: Start
Step 2: Declare variable a, b, c
Step 3: Initialize Variables
3.1 Display “Enter three sides of triangle”
3.2 Read variable a, b, c
Step 4: If a+b Greater than c && a+c Greater than b && b+c Greater than a
4.1 Display “Triangle is valid”
Else
4.2 Display “Triangle is not valid”
Step 4: Endif
Step 5: End

Write an Algorithm to check whether the triangle is equilateral, isosceles or


scalene triangle.
Step 1: Start
Step 2: Declare variable a, b, c
Step 3: Display “Enter three sides of triangle”
3.1 Read variable a, b, c
Step 4: If a equals to b && b equals to c
4.1 Display “All sides are Equal, the given triangle is Equilateral”
else
4.2 If a equals to b OR b equals to c OR c equals to a
4.2.1 Display “Two sides are Equal, the given triangle is Isosceles”
else
4.2.2 Display “Sides are Not Equal, the given triangle is scalene”
4.3 endif
Step 5: Endif
Step 6: End

Write an Algorithm to calculate profit or loss.


Step 1: Start
Step 2: Declare variable cp,sp, amt
Step 3: Initialize Variables
3.1 Set amt0
Step 4: Display “Enter Cost Price and Selling Price”
Step 5: Read variable cp, sp
Step 6: If sp greater than cp
6.1 Set amt  sp-cp
6.2 Display “Profit is :”+amt
else
6.3 If sp equals to cp
6.3.1 Display “No Profit No Loss”
else
6.3.2 Set amt=cp-sp
6.3.3 Display “Loss is “+amt
6.4 endif
Step 7: Endif
Step 8: End

Write an Algorithm to input marks of five subjects Physics, Chemistry,


Biology, Mathematics and Computer. Calculate percentage and grade
according to following:
Percentage >= 90% : Grade A

Percentage >= 80% : Grade B


Percentage >= 70% : Grade C

Percentage >= 60% : Grade D

Percentage >= 50% : Grade E

Percentage < 40% : Grade F

Step 1: Start
Step 2: Declare variable SubMark, Percentage, TotalMark,i
Step 3: Initialize Variables
3.1 Set i1
3.2 Set TotalMark  0
Step 4: Repeate the Steps Until I greater than 5
4.1 Display “Enter subject “+i+”Marks”
4.2 Read Value SubMark
4.3 Set TotalMarkTotalMark+i
4.4 Set i  i +1
Step 5: Set Percentage  (TotalMark)/5
Step 6: If Percentage greater than or equals to 90
6.1 Display “Grade A”
else
6.2 If Percentage greater than or equals to 80
6.2.1 Display “Grade B”
else
6.2.2 If Percentage greater than or equals to 70
6.2.2.1 Display “Grade C”
else
6.2.2.2 If Percentage greater than or equals to 60
6.2.2.2.1 Display “Grade D”
else
6.2.2.2.2 If Percentage greater than or equals to 50
6.2.2.2.2.1 Display “Grade E”
else
6.2.2.2.2.2 Display “Grade F”
6.2.2.2.3 endif
6.2.2.3 endif
6.2.3 endif
6.3 endif
Step 7: Endif
Step 8: End

Write an Algorithm to input basic salary of an employee and calculate its


Gross salary according to following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%

Basic Salary <= 20000 : HRA = 25%, DA = 90%


Basic Salary > 20000 : HRA = 30%, DA = 95%

Step 1: Start
Step 2: Declare variable Bsalary, HRA, DA, Gross_Salary
Step 3: Initialize Variables
3.1 Set Gross_Salary1
Step 4: Read Value Bsalary
Step 5: If Bsalary Less than or equals to 10000
5.1 Set HRA  Bsalary * (20/100)
5.2 Set DA  Bsalary * (80/100)
else
5.3 If Bsalary Less than or equals to 20000
5.3.1 Set HRA  Bsalary * (25/100)
5.3.2 Set DA  Bsalary * (90/100)
else
5.3.3 Set HRA  Bsalary * (30/100)
5.3.4 Set DA  Bsalary * (95/100)

5.4 endif
Step 7: Endif
Step 8: Set Gross_Salary  Bsalary +HRA+DA
Step 9: Display “Gross Salary :”+Gross_Salary
Step 10: End
Write an Algorithm to input electricity unit charges and calculate total
electricity bill according to the given condition:
For first 50 units Rs. 0.50/unit

For next 100 units Rs. 0.75/unit

For next 150 units Rs. 1.20/unit

For unit above 300 Rs. 1.50/unit

An additional surcharge of 20% is added to the bill

Step 1: Start
Step 2: Declare variables unit, amt, total_amt, sur_charge;
Step 3: Initialize Variables
3.1 Set total_amt0
Step 4: Display “Enter total units consumed”
Step 5: Read Value unit
Step 6: If Unit Less than or equals to 50
6.1 Set amt  unit * 0.50
else
6.2 if Unit Less than or equals to 150
6.2.1 Set amt  25 + ((unit-50)*0.75)
else
6.2.2 if Unit Less than or equals to 300
6.2.2.1 Set amt  100 + ((unit-150)*1.20)
else
6.2.2.2 Set amt  280 + ((unit-300)*1.50)
6.2.3 endif
6.3 endif
Step 7: Endif
Step 8: Set sur_charge  amt * 0.20
Step 9: Set total_amt  amt + sur_charge
Step 10: Display “Electricity Bill = Rs ”+ total_amt
Step 11: End

You might also like