You are on page 1of 16

Assignment

Sharda University
Algorithm, Flowchart, Pseudo Code
Programming for Problem Solving

Abhishek Kandel
2021826004
CPP113
Dr. Vivek Kumar Singh

Paper Due Date

Nov 25, 2021


0
Algorithm And Flowchart Assignments
1. The distance between two cities (in km) is input through the keyboard. Write an algorithm and
program to convert and print this distance in meters, feet, inches and centimetres?

Step 1: Start
Step 2: Read the Distance in km
Step 3: Compute Meter = km * 1000
Step 4: Compute Feet = km * 3280.84
Step 5: Compute Inches = km * 39370.1
Step 6: Compute Centimetre = km * 100000
Step 7: Print "Distance in Meter =" Meter
Step 8: Print "Distance in Feet=" Feet
Step 9: Print "Distance in Inch=" Inches
Step 10: End

1
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
2. Two numbers are input through the keyboard into locations a and b. write an algorithm and
program to interchange the contents of a and b.
Step 1: Start
Step 2: Read two numbers a and b
Step 3: Let c= a
Step 4: Let a=b
Step 5: Let b=c
Step 6: print a,b
Step 7: End

2
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
3. Write an algorithm to find whether the number is even or odd.

Step 1: Start
Step 2:Read number n
Step 3: Is n mod 2=0?
If Yes, Print "Even"
else Print "Odd"
Step 4: End

Start

Read n

Yes No
Is n mod 2= 0?

Print Even Print Odd

End

3
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
4. Write an algorithm to print the largest among three numbers.

Step 1 : Start
Step 2: Read the integer number a, b, c
Step 3: Is a>b?
If True Go to Step 4
Else
Go to Step 9.
Step 4: Is a>c?
If true Go to step 5
Else
Go to Step 7
Step 5: Print number a is the Greatest.
Step 6: Go to Step 14
Step 7: Print Number c is the greatest
Step 8: Go to Step 14
Step 9: Is b >a?
If True Go to Step 10
Else
Go to Step 12
Step 10: Is b>c?
If true Go to Step 11
Else
Go to Step 13
Step 11: Print b is the Greatest
Step 12: Go to Step 14
Step 13 : Print Number c is the Greatest
Step 14: End

4
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
5. Write an algorithm to print sum, mult, sub, div of two numbers

Step1: Start
Step 2: Read the two numbers, a and b.
Step 3: Print a + b.
Step 4: Print a - b.
Step 5: Print a * b.
Step 6: If b = 0 Print “undefined”.
Step 7: Else Print a / b
Step 8: End

5
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
6. Write an algorithm to calculate simple interest.

Step 1:Start
Step 2:Read Principal Amount, Rate and Time
Step 3: Compute SI= ((amount*rate*time)/100)
Step 4:Print SI
Step 5:Stop

6
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
7. Write an algorithm to read 3 numbers from the user. Print their sum and average.
Step 1: Start
Step 2 :Read a,b,c
Step 3: Declared a variable "sum" and "Avg".
Step 4 : sum=a+b+c;
Step 5: Avg=sum/3
Step 6:Display "sum " and "Avg".
Step 7 :End .

7
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
8. Write an algorithm to read basic salary from the user and compute HRA – 12% of basic, DA- 64% of
basic, allowance -15% of basic. Also display total salary

Step 1: Start
Step 2: Read the basic Salary BS
Step 3 :Declare variables HRA, DA,AL, Total
Step 4: HRA= BS*0.12
Step 5: DA= BS*0.64
Step 6: AL= BS*0.15
Step 7: Total= HRA +DA+AL
Steo 8: Print Total
End

8
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
9. Write an algorithm to find area and perimeter of square

Step 1: Start
Step 2: Input Side
Step 3: Perimeter= 4*Side
Step 4: area = Side*Side
Step 5: print Perimeter
Step 6: Print area
Step 7: Stop

9
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
10.Write an algorithm to find area and perimeter of circle

Step 1: Start
Step 2: input r
Step 3: let pi = 3.14
Step 4: area = pi * r * r
Step 5: circum = 2 * pi * r
Step 6: print area, circum ,
Step 7: stop

10
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
Algorithm Assignments
1. The current year and the year in which the employee joined the organization are entered through the
keyboard. If the number of years for which the employee has served the organization is greater than 3
then a bonus of Rs. 2500/- is given to the employee. If the years of service are not greater than 3,
then the program should do nothing.

Step 1: Start
Step 2 : Read Current_Year
Step 3 : Read Joined_Year
Step 4 : Declare a variable Year
Step 5: Year = Current_Year -Joined_Year
Step 6: If Year > 3, Then Goto Step 7
Else
Go to Step 8
Step 7: Print " You are Eligible to get Bonus of 2500"
Step 8: Stop

2. In a company an employee is paid as under:


If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic
salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of
basic salary. If the employee's salary is input through the keyboard write a program to find his
gross salary.

Step 1: Start
Step 2: Input basic_salary
Step 3: Declare the Variable HRA, DA, gross_salary
Step 4: If basic_salary <=1500, then
Go to Step 5
Else
Goto Step 10
Step 5 : HRA= basic_salary * 0.1
Step 6: DA= basic_salary* 0.9
Step 7: gross_salary =basic_salary +HRA +DA
Print 8: print gross_salary
Step 9: Goto Step 14
Step 10 : HRA= 500
Step 11: DA= basic_salary* 0.98
Step 12: gross_salary =basic_salary +HRA +DA
Step 13: Print gross_salary
Step 14: End

11
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
3. The marks obtained by a student in 5 different subjects are input through the keyboard. The student
gets a division as per the following rules:

Percentage above or equal to 60 - First division


Percentage between 50 and 59 - Second division
Percentage between 40 and 49 - Third division Percentage less than 40 - Fail
calculate the division obtained by the student.

Step 1: start
Step 2 : Enter the marks m1, m2, m3, m4, m5
Step 3: Declare the Variable Total, Per,
Step 4: Total = m1+m2+m3+m4+m5
Step 5: Per = total/5
Step 6: If Per>=60 Then $Div= "First"
Elseif
Per>=50 or Per<60 then $Div= "Second"
Elseif
Per>=40 or Per<50 then $Div= "Third"
Else
$Div =" Fail"
Step 7: Print $ Div.
Step 8: Stop

12
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
4. Calculate salary

Step 1 : Start
Step 2: Read $Education_Level, "PG" for Post-Graduate, "UG" for Under-Graduate
Step 3: Read $Gender, "M" for male, "F" for female
Step 4: Read Service_Year
Step 5: Declare a Variable S for Salary
Step 6: If $Education_Level ="PG" AND Service_Year >=10 AND $Gender ="M" Then S=15000
Elseif
$Education_Level ="UG" AND Service_Year >=10 AND $Gender ="M" Then S=10000
Elseif
If $Education_Level ="PG" AND Service_Year <10 AND $Gender ="M" Then S=10000
Elseif
If $Education_Level ="UG" AND Service_Year <10 AND $Gender ="M" Then S=7000
Elseif
If $Education_Level ="PG" AND Service_Year >=10 AND $Gender ="F" Then S=12000
Elseif
$Education_Level ="UG" AND Service_Year >=10 AND $Gender ="F" Then S=9000
Elseif
If $Education_Level ="PG" AND Service_Year <10 AND $Gender ="F" Then S=10000
Else
If $Education_Level ="UG" AND Service_Year <10 AND $Gender ="F" Then S=6000
Step 7: Print "Salary =" S
Step 6: Stop

13
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
5. If the ages of Ram, Shyam and Ajay are input through the keyboard. determine the youngest of the
three.

Step 1 : Start
Step 2: Read the age of Ram, Shyam and Ajay be a, b, and c respectively.
Step 3: Is a<b?
If True Go to Step 4
Else
Go to Step 9.
Step 4: Is a<c?
If true Go to step 5
Else
Go to Step 7
Step 5: Print "Ram is the Youngest of Three"
Step 6: Go to Step 14
Step 7: Print "Ajay is the Youngest of Three"
Step 8: Go to Step 14
Step 9: Is b <a?
If True Go to Step 10
Else
Go to Step 12
Step 10: Is b<c?
If true Go to Step 11
Else
Go to Step 13
Step 11: Print "Shyam is the Youngest of Three"
Step 12: Go to Step 14
Step 13 : Print "Ajay is the Youngest of Three"
Step 14: End

6. Two numbers are input through the keyboard into locations C and D. write an algorithm and program
to interchange the contents of C and D

Step 1: Start
Step 2: Read two numbers C and D
Step 3: Let a= C
Step 4: Let C=D
Step 5: Let D=a
Step 6: print C,D
Step 7: End

7. Write an algorithm to find whether the number is even or odd.

Step 1: Start
Step 2:Read number n
Step 3: Is n mod 2=0?
If Yes, Print "Even"
else
Print "Odd"
Step 4: End

14
SUBMITTED BY ABHISHEK KANDEL
(2021826004)
8. Write algorithm to check whether a triangle is valid or not, when the three angles of the triangle are
entered through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180
degrees.

Step 1: Start
Step 2: Read the three angles of Triangle a, b, c
Step 3 : Declare a variable sum
Step 4: sum= a+b+c
Step 5: if sum = 180 THEN
Print " Valid Triangle"
Else
Print " Invalid Triangle"
Step 6: Stop

9. A company insures its drivers in the following cases: −


If the driver is married.
If the driver is unmarried, male & above 30 years of age.
If the driver is unmarried, female & above 25 years of age.

Step 1: Start
Step 2: Read Marital_Status, age, Gender
Step 3: If Marital_Status ="Married" Or (Gender ="Male" AND Age > 30) Or (Gender ="Female"
AND age > 25) Then
Print " You are Insure"
Else
Print "You are Not Insure"
Step 4: End

10. Any year is input through the keyboard. Determine whether the year is a leap year or not. (Hint: Use
the % (modulus) operator)

Step 1: Start
Step 2: Read the Year
Step 3: If Year % 4 = 0 Then Go To step 4 Else Goto Step 6
Step 4: Print " Its Leap Year"
Step 5: Goto Step 7
Step 6: Print "Its Not Leap year"
Step 7: End

15
SUBMITTED BY ABHISHEK KANDEL
(2021826004)

You might also like