0% found this document useful (0 votes)
18 views

Problem Solving_Q_Solutions

The document outlines various problem-solving techniques including algorithms and flowcharts for tasks such as finding the square of a number, checking if a number is odd or even, and categorizing age groups. It also defines key concepts in problem-solving, characteristics of algorithms, and provides examples of pseudocode and C++ programs. Additionally, it differentiates between algorithms and pseudocode and lists symbols used in flowchart design.
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)
18 views

Problem Solving_Q_Solutions

The document outlines various problem-solving techniques including algorithms and flowcharts for tasks such as finding the square of a number, checking if a number is odd or even, and categorizing age groups. It also defines key concepts in problem-solving, characteristics of algorithms, and provides examples of pseudocode and C++ programs. Additionally, it differentiates between algorithms and pseudocode and lists symbols used in flowchart design.
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/ 6

PROBLEM SOLVING QUESTIONS & ANSWERS

1. Write an algorithm to find the square of a number. Display the pictorial representation of the
algorithm using a flowchart.
Algorithm
 Start: Begin the process. (T)
 Input: Accept a number n from the user. (I/O)
 Process: Compute the square of the number as n2. (P)
 Output: Display the result n2. (I/O)
 End: Terminate the process. (T)
Pictorial Representation

Start

Accept number n

Compute n2

Display Result

End

2. Draw a flowchart to solve the problem of a non-functioning light bulb.

Start

Is the bulb No Is power Yes Contact Electrician


broken? on?

No
Yes

Replace Bulb Turn on power

End
3. Present an algorithm to check whether a number is odd or even in pseudo code and flowchart.
Pseudo code
1. Start
2. Input a number (n)
3. Check if n % 2 == 0:
 If True, then n is Even
 Else, n is Odd
4. Display the result (Odd or Even)
5. End

Flow Chart

Start

Input Number n

Is n% 2 False
N is Odd
==0?

True

N is Even Display Result

End

4. Write an algorithm where multiple conditions are checked to categorize a person as either child
(<13), teenager (>=13 but <20) or adult (>=20), based on age specified.
Algorithm
1. Start (T)
2. Accept a number for the age as input. (I/O)
3. Decide if age is less than 13: (P)
Display "Child" (P)
4. Else if age is greater than or equal to 13 and less than 20: (D)
Display "Teenager" (P)
5. Else:
Display "Adult" (P)
6. End (T)
5. Describe a flowchart to accept 5 numbers and find their average.
Here is a textual description of the flowchart steps to calculate the average of 5 numbers:
Flowchart Steps
1. Start: Begin the process. (T)
2. Initialize Variables: Set “sum = 0” and “count = 0”. (P)
3. Input Number: Accept a number from the user. (I/O)
4. Update Variables: Add the number to “sum” and increment “count” by 1. (P)
5. Decision: Is “count == 5”? (D)
a. No: Go back to Step 3 to input the next number.
b. Yes: Proceed to Step 6.
6. Calculate Average: Compute “average = sum / 5”. (P)
7. Output Average: Display the calculated average. (I/O)
8. End: Terminate the process. (T)
6. Write pseudo code, draw flowchart to accept numbers until the user enters 0, and then find
their average.
Pseudo Code
Step1: Start (T)
Step2: Initialize Sum = 0, Count = 0 (P)
Step3: Input n (I/O)
Step4: If n != 0 (D)
Step5: Sum = Sum + Number, Count = Count + 1 (P)
Step6: If n ==0 & Count > 0 Then (D)
Step7: Average = Sum / Count (P)
Step8: Display Average (I/O)
Step9: End (T)
Flow Chart

Start

Sum = 0, Count = 0

Input n

YES Sum = Sum + n


Is n != 0? Count = Count + 1

NO

Is n == 0 &&
Count > 0 Average = Sum /
Display Count End
Count
7. Write pseudo code that reads two numbers divide one by another, and display the quotient.
Pseudo Code
Step1: Start
Step2: Input num1, num2
Step3: If num1 > num2
Step4: Quotient = num1 / num2
Step5: Else, Quotient = num2/num1
Step6: Display Quotient
Step7: End
8. Write an algorithm to find the greatest between two different numbers entered by the user.
Step1: Start
Step2: Input numbers num1, number2
Step3: Check if num1 is greater than num2
Step4: Display num1 is the greatest
Step5: Else, Display num2 is the greatest
Step6: End
9. Write a pseudo code that performs the following: Ask a user to enter a number. If the number is
between 5 and 15, write the word GREEN. If the number is between 15 and 25, write the word
BLUE. If the number is between 25 and 35, write the word ORANGE. If it is any other number,
write that ALL COLOURS ARE BEAUTIFUL.
Pseudo Code
Step 1: Start
Step 2: Input Num
Step 3: If Num >= 5 && Num <= 15:
Step 4: Display "GREEN"
Step 5: Else If Num > 15 && Num <= 25:
Step 6: Display "BLUE"
Step 7: Else If Num > 25 && Num <= 35:
Step 8: Display "ORANGE"
Step 9: Else, Display "ALL COLOURS ARE BEAUTIFUL"
Step 10: End
10. What is an Algorithm?
An algorithm is a well-defined, step-by-step procedure or set of instructions designed to solve a
problem or perform a specific task. Or An algorithm specifies a series of steps that perform a
particular computation or task.
11. Define the concept of problem solving.
Problem solving is the process of identifying a problem, developing an algorithm for the
identified problem and finally implementing the algorithm to develop a computer program.
12. What are the steps involved in problem solving?
a. Analyze the problem: to figure out what are the inputs that our program should accept
and the outputs that it should produce.
b. Developing an Algorithm: representing the solution in a sequence of steps (in Natural
language) before coding it.
c. Coding: to convert the algorithm into the format that could be understood by the
computer to generate the desired solution.
d. Testing and Debugging: to ensure all necessary requirement are met and the provided
solution is satisfactory.
13. Define the following terms:
a. Sequence Flow: using sequences to present a list of instructions to be followed one
after the other, step by step.
b. Selection Flow: A selection is used to make choices based on information.
c. Iteration Flow: Iteration is the process of repeating sections of a program to achieve a
particular target or goal.
d. Variables: Variables are containers for storing data values.
14. List the components of algorithm you familiar with
a. Input
b. Process
c. Output
15. List 5 characteristics of algorithm
a. Precision — the steps are precisely stated or defined.
b. Uniqueness — results of each step are uniquely defined and only depend on the input
and the result of the preceding steps.
c. Finiteness — the algorithm always stops after a finite number of steps.
d. Input — the algorithm receives some input.
e. Output — the algorithm produces some output.
16. List 5 data types you know with examples
a. int - such as 123 or -123
b. double - such as 19.99 or -19.99
c. char - such as 'a' or 'B'.
d. string - such as "Hello World".
e. bool - true or false
17. Code a program that outputs “This is the end of this semester” in C++.
#include <iostream>
using namespace std;
int main() {
cout << "This is the end of this semester" << endl;
return 0;
}
18. What are the two major ways of representing an algorithm?
a. Pseudo code is a detailed description of instructions that a computer must follow in a
particular order. It is intended for human reading and cannot be executed directly by
the computer.
b. Flowchart is a visual representation of an algorithm made up of boxes, diamonds and
other shapes, connected by arrows.
19. Design a computer program that sum three numbers entered from the keyboard
#include <iostream>
using namespace std;
int main() {
int num1, num2, num3, sum;
sum = num1 + num2 + num3;
cout << “The sum is: “<<sum << endl;
return 0;
}
20. Differentiate between an algorithm and a pseudocode.
Key Algorithm Pseudocode
Difference
Purpose Algorithms provides Pseudocode is a way
a solution to express that
solution.
Format More formal, Programming-like
mathematical or syntax
logical notation

21. List 3 Symbols used for designing a flowchart


a. Process
b. Terminal
c. Input/Output
d. Flow lines
e. Decision

You might also like