CHAP 5: INTRODUCTION TO
PROBLEM SOLVING
TYPE A: SHORT ANSWER QUESTIONS
1. What are the phases of program solving cycle?
Ans: The Problem-Solving Cycle includes a total of five
steps:
● Define the problem;
● Brainstorm solutions;
● Pick a solution/solutions;
● Implement the solution;
● Review the results.
2. What do you do while analysing a problem?
Ans: We identify the reasons and causes of the problem
as well as what to be solved. So this step involves a
detailed study of the problem and requires the need to
follow the core functionality of the solution. In this step
input and output, elements should be produced to get
the solution.
3. What is done during coding phase?
Ans: During the coding phase, developers analyze the
feasibility of each coding language and begin
programming according to coding specifications.
Without proper coding, the requirements won't be
fulfilled. It is also called the development phase.
4. What is testing and debugging?
Ans: Testing is the process using which we find errors
and bugs. Debugging is the process using which we
correct the bugs that we found during the testing
process.
5. Distinguish between a condition and a statement.
Ans: A statement is a phrase that commands the
computer to do an action.Whereas, a condition is a
phrase that describes a test for the statement.
6. Dram a flowchart for conditional statement.
7. Both conditional statement and iteractive statement
have a condition and a statement. How do they differ?
Ans: Conditional Statement: Statements shall only be
made once if the requirement is true.
Iterative Statement: This tests a condition repeatedly
and renders a declaration until it is false.
8. What is decomposition?
Ans: Decomposition involves breaking of a complex
problem into smaller parts that are more manageable
and easier to understand. The smaller parts can then be
examined and solved, or designed individually, as they
are simpler to work with.
9. Name some tools used for problem solution
development.
Ans:
● The design of a solution includes a sequence of
well-defined steps that will produce the desired result
(output).
● Eg: Algorithms and flowcharts are used as design
tools and represent the solution to a problem.
10. What is the difference between an algorithm and a
program?
Ans: Algorithm:
● Algorithm is for human readers to understand.
● Knowledge of English is needed.
● Easy to understand.
Program:
● Program is for the computers to execute directly.
● Knowledge of programming language is required.
● It is difficult to understand.
11. What is dry run? How is it useful? (Deleted)
12. What is trace table? (Deleted)
______**_______
Type- B
8Q. To find the area and perimeter of a rectangle.
Answer :-
Algorithm :-
1. Input length 2. Input width 3. Perimeter 2 * ( length +
width ) 4. Area length * width 5. Print perimeter 6. Print
Area 7. Stop
Pseudocode :-
L = input "length of rectangle" W = input "width of
rectangle" Perimeter = 2 * ( L + W ) Area = L * W Display
Perimeter Display Area
Flow Chart :-
9Q. To calculate the area and the circumference of
circles.
Answer :-
Algorithm :-
1. Input radius
2. Circumference 2 * 3.14 * radius
3. Area 3.14 * radius ** 2
4. Print Circumference
5. Print Area
6. 7. Stop
Pseudocode :-
R = input "Radius of Circle"
Circumference = 2 * 3.14 * radius
Area = 3.14 * radius ** 2
Display Circumference
Display Area
Flow Chart :-
10Q. To calculate the simple interest.
Answer :-
Algorithm :-
1. Start
2. Input principal
3. Input rate
4. Input time
5. Simple interest principal * rate * time
6. Print simple interest
7. Stop
Pseudocode :-
P = input "principal value "
R = input " rate "
T = input "time "
Si = p * r * t
Display si
Flow Chart :-
11Q. To check whether a year is a leap year or not.
Answer :-
Algorithm :-
1. Start
2. Input Year
3. If year % 4 == 0
Print "leap year "
Else
Print " not leap year "
Pseudocode :-
Y = input " a year"
If y is full divisible by 4
Display y is leap year
Else
Display y is not leap year
Flow Chart :-
12Q. To check if a number is a positive or negative
number.
Answer :-
Algorithm :-
1. Start
2. Input number
3. If number < 0
Print "number is negative"
Else
Print "number is positive"
4. Stop
Pseudocode :-
N = input "A number "
If n is smaller than 0
Display " n is negative number "
Else
Display " n is positive number "
Flow Chart :-
13Q. To check if a number is an odd or even number.
Answer :-
Algorithm :-
1. Start
2. Input number
3. If number % 2 == 0
4. Print "number is even"
5. Else
6. Print "number odd"
7. Stop
Pseudocode :-
N = input "A number "
If n is fully divisible by 2
Display " n is even number "
Else
Display " n is positive number "
Flow Chart :-
14Q. To categorise a person as either child (<13),
teenager (> 13 but <20) or adult (20), based on age
specified.
Answer :-
Algorithm :-
1. Start
2. Inputage 3. If age < 13
Print
"Child" Elif
age >= 20
Print "adult"
Else
Print "teenager"
4. Stop
Pseudocode :-
A = input "Age "
If a is smaller than 13
Display " Child "
Elif a is greater or equal 20
Display "adult"
Else
Display " teenager "
Flow Chart :-
15Q. To print all natural numbers up to n.
Answer :-
Algorithm :-
1. Start
2. Input n
3. For I in range ( 1, n + 1 )
Print I
4. Stop
Pseudocode:-
N = input "N "
For I in range ( 1 to n + 1 )
Display I
Flow Chart :-
16Q. To print n odd numbers.
Answer :-
Algorithm :-
1. Start
2. Input n
3. For I in range ( 1 , 2 * n + 1 ) If I % 2 != 0 :
Print I
5. Stop
Pseudocode :-
N = input n
For I in range ( 1 to 2 * n +1)
If I is not divisible by 2
Display I
Flow Chart :-
17Q. To print square of a number.
Answer :-
Algorithm :-
1. Start
2. Input a number
3. Square = number ** 2
4. Print Square
5. Stop
Pseudocode :-
N = input "number "
Square = n * n
Display square
Flow Chart :-
18Q. To accept 5 numbers and find their average.
Answer :-
Algorithm :-
1. Start
2. Input a , b, c , d, e
3. Sum a + b + c + d + e
4. Average Sum / 5
5. Print Average
6. Stop
Pseudocode :-
A = input first number
B = input second number
C = input third number
D = input fourth number
E = input fifth number
Sum = a + b + c + d + e
Average = Sum / 5
Display Average
Flow Chart :-
19Q. To accept numbers till the user enters and then
find their average.
Answer :-
Algorithm :-
1. Start
2. Sum = 0
3. Count = 0
4. While True
Input number
Sum += number
Count += 1
Input choice to quit enter yes
If choice == yes
Break
5. Average = Sum / count
6. Print average
7. Stop
Pseudocode :-
Sum = 0
Count = 0
While True
N = input "Number "
Sum is equal to sum + number
Count is equal to count + number
Choice = input "to quit enter quit"
If choice is equal to quit
Break
Average = sum /
count Display Average
Flow Chart :-
20Q. To print squares of first n numbers.
Answer :-
Algorithm:-
1. Start
2. Input a number
3. For I in range ( number +1 )
Square = I ** 2
Print Square
4. Stop
Pseudocode :-
N = input "a number"
For I in range 0 to n + 1
Square = I ** 2
Display square
Flow Chart :-
21Q. To print the cube of a number.
Answer :-
Algorithm:-
1. Start
2. Input a number
3. Cube = number ** 3
4. Print cube
5. Stop
Pseudocode:-
N = input a number
Cube = n ** 3
Display cube
Flow Chart :-
22Q. To print to print cubes of first n numbers.
Answer :-
Algorithm:-
1. Start
2. Input a number
3. For I in range ( number +1 )
Cube = I ** 3
Print cube
4. Stop
Pseudocode :-
N = input "a number"
For I in range 0 to n + 1
Cube = I ** 3
Display cube
Flow Chart :-
23Q. To find sum of n given numbers.
Answer :-
Algorithm :-
1. Start
2. Sum = 0
3. While True
Input number
Sum += number
Choice = input to quit enter quit
If choice == quit
Break
4. Print Sum
5. Stop
Pseudocode :-
Sum = 0
While True
N = input a number
Sum equal to sum + n
Choice = input to quit enter quit
If choice is quit
Break
Display sum
Flow Chart :-
24Q. To find factorial of a given number.
Answer :-
Algorithm :-
1. Start
2. Input number
3. Fact = 1
4. For I in range number + 1
Fact *= I
5. Print Fact
Pseudocode :-
N = input a number
Fact is 1
For I in rang n +1
Fact equal to fact * I
Display Fact
Flow Chart :-
24Q. To find factorial of a given number.
Answer :Algorithm
:-
1. Start
2. Input number
3. Fact = 1
4. For I in range number + 1 Fact *= I
5. Print Fact
Pseudocode :-
N = input a number
Fact is 1
For I in rang n
+1 Fact
equal to fact
*I
Display Fact
Flow Chart :-
25Q.Given the following pseudo code:
Use variables sum, product, number1,
number2 of type real display "Input two
numbers" accept number1, number2
sum number1 + number2 print "The
sum is", sum product number1*
number2 print "The Product is ",
product end program
Draw a flow chart for the same and dry run the given
pseudocode if it is working fine
26Q. Given the following pseudo code:
Use variables: choice, of the type character
ans, number1, number2, of type integer display "choose
one of the following"
display "m for multiply" display "a for add" display "s
for subtract" accept choice
display "input two numbers you want to use" accept
number1, number 2 if choice
m then ans number1 number2 if choice a then ans
number1 + number 21 if choices then ans number1 -
number2 display ans
Draw a flow chart for the same and dry run the given
pseudocode if it is working
27Q. Given the following pseudo code:
Use variables: mark of type integer
If mark> 80, display "distinction" If mark > 60 and mark
< 80, display "merit"
If mark > 40 and mark < 60,
display "pass" If mark 40
display, "fail"
Draw a flow chart for the same and dry run the given
pseudocode if it is working fine.
28Q.Given the following pseudo code:
Use variables: category of type character
Display "input category" Accept category
If category= 'U'
Display "insurance is not available"
Else If category= 'A' then
Display "insurance is double"
Else If category= 'B' then
Display "insurance is normal"
Else If category= 'M' then
Display "insurance is medically dependent"
Else
Display "entry invalid"
Draw a flow chart for the same and dry run the given
pseudocode if it is working fine.
Flowchart
29Q. Given the following pseudo code:
Use variable: number of type real
DISPLAY "Type in a number or zero to stop"
ACCEPT number
WHILE number 0
Square number number
DISPLAY "The square of the number is", square
DISPLAY "Type in a number or zero to stop"
ACCEPT number
ENDWHILE
Draw a flow chart for the same and dry run the given
pseudocode if it is working fine.
Answer: