0% found this document useful (0 votes)
10 views8 pages

Problem Solving and Python Programming Question and Answers Unit-I

The document provides a comprehensive overview of algorithms, pseudo code, flowcharts, and programming concepts relevant to problem-solving and Python programming. It includes definitions, contrasts between concepts, and examples of algorithms and pseudo codes for various tasks. Additionally, it covers the building blocks of algorithms, characteristics of algorithms, and approaches to problem-solving.

Uploaded by

GIJENDRASHIVAN K
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)
10 views8 pages

Problem Solving and Python Programming Question and Answers Unit-I

The document provides a comprehensive overview of algorithms, pseudo code, flowcharts, and programming concepts relevant to problem-solving and Python programming. It includes definitions, contrasts between concepts, and examples of algorithms and pseudo codes for various tasks. Additionally, it covers the building blocks of algorithms, characteristics of algorithms, and approaches to problem-solving.

Uploaded by

GIJENDRASHIVAN K
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/ 8

HINDUSTHAN COLLEGE OF ENGINEERING AND TECHNOLOGY

DEPARTMENT OF INFORMATION TECHNOLOGY


19CS1151 / Problem Solving and Python Programming
Question and Answers
Unit-I : Part A
1. Summarize about Algorithm
 An algorithm is a step by step procedure or formula for solving a problem, based on conducting a
sequence of specified action.
 Algorithm is an ordered sequence of finite, well defined, unambiguous instructions for completing a
task.

2. Contrast between pseudo code and flowchart.


Flowchart is usually a graphical representation, where as pseudo-code is something written
in a language. Both show the step by step procedure for solving a problem. One is graphical while other is text
based.

3. Discuss a pseudo code to accept two numbers add the numbers and to print the result.
BEGIN
GET X,Y
ADD Z=X+Y
PRINT Z
END

4. Describe about the building blocks of an algorithm.


Three building blocks are Sequence, Selection, and Iteration.
 Sequence is an action in which one or more instructions that the computer performs in sequential order
(from first to last).
 Selection is a Decision making choice among several actions.
 Iteration can be a Loop in which one or more instructions that the computer performs repeatedly.

5. List the categories of Programming languages.


 Procedural or Functional Programming Language
 Object Oriented Programming Language

6. Mention the characteristics of an algorithm.


 The steps in the algorithm must be simple and precise.
 It must not be ambiguous.
 Algorithm should be written in sequence.
 It should have an end.
 Algorithm must solve the given problem.

7. Contrast between pseudo code and algorithm.


An algorithm is a systematic logical approach used to solve problems in a computer
while Pseudocode is the statement in plain English which may be translated later into a programming
language (program). An algorithm is the semantic while the pseudo-code is just a syntax of the
communication about solving a problem.

1
8. Define the term hardware and software.
Hardware is any physical device used in or with your machine.
Examples of hardware devices in the computer are output devices like printer, monitor, input devices
like keyboard, and mouse.
Software is a collection of code installed onto your computer's hard drive.

9. Define function.
Function is a sub program which consists of block of code (set of instructions) that performs a particular
task. For complex problems, the problem is been divided into smaller and simpler tasks during algorithm
design.

10. Define top-down approach. Give an example.


Top down approach divides a problem into smaller units and then solve it. In this approach, first we
develop the main module and then the next level modules are developed. This procedure is continued until
all the modules are developed.
Example:
Calculator

ADD SUBTRACT MULTIPLY

11. Define bottom-up approach. Give an example


Bottom-up approach Starts from solving small modules and adding them up together. In this approach, bottom
level modules developed first (Lower level module developed, tested and debugged). Then the next
module developed, tested and debugged. This process is continued until all modules have been completed.
Example:
Calculator

ADD SUBTRACT MULTIPLY

12. Define flowchart and list its uses.


Flow chart is defined as graphical or diagrammatic representation of the logic for problem solving. The
purpose of flowchart is making the logic of the program clear in a visual representation. A flowchart is a
picture of the separate steps of a process in sequential order.
Uses

 Problem solving
 Proper documentation
 Instant communication
 Effective analysis

2
13. Draw a flowchart to calculate average of three numbers.

14. Write an algorithm to find greater of 2 numbers.


Step 1: Start
Step 2: Read a, b
Step 3: If a > b then
Display “a is the largest number”.
Otherwise.
Display “b is the largest number”.
Step 4: Stop

15. Write a pseudo code to check whether the given number is positive or negative.

Step 1: Start.
Step 2: Read n
Step 3: If n>=0 then
Display “n is the Positive number”.
Otherwise.
Display “n is the Negative number”.
Step 4: Stop

16. Write an algorithm for Celsius to Fahrenheit and vice versa.


Step 1.Start
Step 2.Read the temperature in degree centigrade (C)
Step 3.Convert the centigrade to Fahrenheit using the formula F=9/5*C+32
Step 4.Print the Celsius and Fahrenheit value.
Step 5. Read the temperature in degree Fahrenheit (F)
Step 6. Convert the Fahrenheit to the centigrade using the formula C=5/9*(F-32)
Step 7.Print the Fahrenheit and Celsius value
Step 8. Stop
3
Unit- I : Part-B

17. Explain in detail the building blocks of algorithm with an example. Ans: Pg.No 1.5 to 1.8

18. Discuss about iteration. Write an algorithm, pseudo code and draw the flowchart to find the
factorial of a given number. Ans: Pg.no: 1.8 &1.32,

19. Write an algorithm, pseudo code and draw a flowchart to find minimum in a list.
Ans :Pg.no 1.18 to 1.20

20. Draw a flow chart and write an algorithm, pseudo code to check whether a given number is prime
or not. Ans: Pg.no 1.34, 1.48

21. Draw a flowchart and write an algorithm, pseudo code and to find the sum of first n natural
numbers. Ans: Pg.no 1.36, 1.55

22. Draw a flowchart and write an algorithm, pseudo code to insert a card in a list of sorted cards.
Ans: Pg.No 1.20 to 1.24

23. Draw a flowchart and write an algorithm, pseudo code to find the largest of three numbers.
Ans: Pg.No 1.7, 1.9, 1.14

24. Draw a flowchart and write an algorithm, pseudo code guess an integer number in a range.
Ans: Pg.no 1.24 to 1.27

25. Draw a flowchart and write an algorithm, pseudo code to find whether the given number is odd or
even. Ans: Pg.No 1.31, 1.35

26. Draw a flowchart and write an algorithm, pseudo code for Towers of Hanoi.
Ans: Pg.No 1.27 to 1.29

4
Unit - I : PART-C

27. Draw flowchart and write an algorithm to find


i) Whether a person is eligible to vote or not
Algorithm:
Step 1: Start
Step 2: Read the age of a person (age)
Step 3: if age > 18 then goto Step 5
Step 4: Print “Person is not eligible for voting” and goto Step 6
Step 5: Print “Person is eligible for voting”
Step 6: Stop
Flowchart:

ii)Whether the given year is leap or not.


Algorithm:
Step 1 : Start
Step 2 : Read Enter Any Year as Y
Step 3 : Check if ( Y%4 = = 0 AND Y %100 != 0 OR Y%400 == 0) then
Write "Given Year is Leap Year"
Otherwise:
Write "Given Year is NOT Leap Year"
Step 4 : Stop

5
Flowchart:

28. Write Draw flowchart and write an algorithm to solve a quadratic equation.
Algorithm
Step 1. Start
Step 2. Read a, b, c
Step 3. Calculate d = SQRT(b * b – 4 * a * c)
Step 4. Calculate r1 = (-b + d ) / (2 * a)
Step 5. Calculate r2 = (-b - d ) / (2 * a)
Step 4. Write r1, r2
Step 5. Stop

Flowchart

6
29. Describe the algorithm to find the simple interest and draw the flowchart for the same.
Algorithm
Step 1. Start
Step 2. Read P, N, R [Principle amount, Number of years, Rate of interest]
Step 3. Compute SI = P * N * R / 100
Step 4. Write SI
Step 5. Stop
Flowchart :

30. Draw flowchart and write an algorithm to find the net salary of an employee.
Algorithm
Step 1: Start
Step 2: Read Basic Salary as basic
Step 3: Calculate Dearness Allowance as da = (10*basic)/100
Step 4: Calculate Travelling Allowance as ta = (12*basic)/100
Step 5: Calculate House Rent Allowance as hra = (20*basic)/100
Step 6: Calculate Gross Salary as gs = basic + da + ta + hra
Step 7: Calculate Tax as tax=gs*9/100
Step 8: Calculate Net Salary as ns = gs - tax
Step 9: write „Net Salary‟, ns
Step 10: Stop

7
Flowchart:

31. Draw flowchart and write an algorithm to find the area of circle and rectangle.
Algorithm Algorithm
Step 1. Start Step 1. Start
Step 2. Read Radius Step 2. Read Length, Breadth
Step 3. Compute Area = 3.14 * Radius * Radius Step 3. Compute Area = Length * Breadth
Step 4. Write Area Step 4. Write Area
Step 5. Stop Step 5. Stop
Flowchart Flowchart

You might also like