chapter 4
Answer
Below are the steps which we need to follow:
1. Start
2. Input a, b
3. Divide = a/b
4. Output Divide
5. Stop
Question 2,
• Create variables ‘p1’ and ‘p2’ to store how many times player1 and player2 has
won
respectively. And variable ‘coin’ to store user input
• For p1 < 3 and p2 < 3
• INPUT coin
• If coin == 1
• p1 = p1 +1
• else if coin ==2
• p2 = p2 + 1
• If p1 == 3
• DISPLAY P1 TAKES THE CAKE
• Else
Question 3
Algorithm:
1. set i = 1
• while i*5 <= 25
• i = i + 1
• print i*5
Question 4
Loops repeat a set or sequence of instructions until a condition is met which stops
the loop.
Loop to print numbers from 1 to 10:
num = 1;
for (num = 1; num<=10; num++)
{
print num;
}
Question 5
Question 5
Create variable ‘total’ and ‘receive’ to
Create variable ‘total’ and ‘receive’ to store the total amount of money collected
and the money store the total amount of money collected and the money given by
relative respectively.given by relative respectively.
• Ask a relative to input money they are willing to give (10, 20, or 50) and store
it in the Ask a relative to input money they are willing to give (10, 20, or 50)
and store it in the receivereceive
• Calculate total = total + receiveCalculate total = total + receive
• If total < 200 go to step 2, else gIf total < 200 go to step 2, else go to step
5o to step 5
• ENDEND
Question 6
Question 6
Pseudocode:
Pseudocode:
Declare variables bill, gstbill, price and quantity.
Declare variables bill, gstbill, price and quantity.
Input the quantity of item and store it in quantity
Input the quantity of item and store it in quantity
Input price of item and store it in price
Input price of item and store it in price
Bill = quantity * price
Bill = quantity * price
gstbill = bill + 0.05 * bill
gstbill = bill + 0.05 * bill
Print bill
Print bill
Print gstbill
Print gstbill
Question 7
Question 7
part a
part a
Pseudocode:
Pseudocode:
Declare variable phy, com and maths
Declare variable phy, com and maths
INPUT com
INPUT com
INPUT phy
INPUT phy
INPUT maths
INPUT maths
part b
part b
Pseudocode:
Pseudocode:
Declare variable agg
Declare variable agg
Agg = phy + maths + com;
Agg = phy + maths + com;
part c
part c
This Pseudocode is continued from (ii):
This Pseudocode is continued from (ii):
Declare variable perc
Declare variable perc
Perc = (ag
Perc = (aggregate / 300 ) X 100gregate / 300 ) X 100
Question 8
Question 8
Start
Start
• Input variables a and bInput variables a and b
• Read variables a and bRead variables a and b
• If a > bIf a > b
• Display a is the largest numberDisplay a is the largest number
• ElseElse
• Display b is the largest numberDisplay b is the largest number
• StopStop
Question 9
Question 9
Declare a variable choice
Declare a variable choice
• Ask the user to input a number and store it in Ask the user to input a number and
store it in variable choicevariable choice
• If choice >= 5 and choice <15 display GREENIf choice >= 5 and choice <15 display
GREEN
• If choice >=15 and choice <25 display BLUEIf choice >=15 and choice <25 display
BLUE
• If choice >=25 and choice <35 display ORANGEIf choice >=25 and choice <35 display
ORANGE
• Else display ALL COLOURS ARE BEAUTIFULElse display ALL COLOURS ARE BEAUTIFUL
Question 10
Question 10
Declare variables num1, num2, num3, num4, min and max
Declare variables num1, num2, num3, num4, min and max
Ask
Ask user to input 4 numbers and store it on variables num1, num2, num3 and num4user
to input 4 numbers and store it on variables num1, num2, num3 and num4
If num1 >= num2, set max = num1 and min = num2
If num1 >= num2, set max = num1 and min = num2
If num3 > max, set max = num3
If num3 > max, set max = num3
If num4 > max set max = num4
If num4 > max set max = num4
If num3 < min, set min = num3
If num3 < min, set min = num3
If num4 < min, set min = num4
If num4 < min, set min = num4
Display min and max
Display min and max
Question 11
Question 11
Declare variables units and bill
Declare variables units and bill
• Ask user to input units and store it in variable unitsAsk user to input units and
store it in variable units
• If units <= 100, calculate bill = (units x 5) + 75If units <= 100, calculate bill
= (units x 5) + 75
• Else If units > 100 and units <= 250, calculate bill = (100 x 5) + ((units Else
If units > 100 and units <= 250, calculate bill = (100 x 5) + ((units –– 100) x
100) x 10) +7510) +75
• Else calculate bill = (100 x 5) + (150 x 10) + ((units Else calculate bill = (100
x 5) + (150 x 10) + ((units –– 250) x 20) + 75250) x 20) + 75
• Display billDisplay bill
Question 12
Question 12
Conditionals are those features of programming language which depends on operators
to evaluate
Conditionals are those features of programming language which depends on operators
to evaluate an expression and executes instructions depending upon an expression
and executes instructions depending upon the outcome of the evaluation. the outcome
of the evaluation. Conditionals make programming much more powerful and are used to
decide the flow of execution Conditionals make programming much more powerful and
are used to decide the flow of execution based on different conditions.based on
different conditions.
Question 13
Question 13
Rounded rectangles or oval are used to represent the start and stop of the
flowchart or
Rounded rectangles or oval are used to represent the start and stop of the
flowchart or process.process.
• Parallelograms are used to represent data input and outputParallelograms are used
to represent data input and output
• Rectangles are used to represent process step for calculationsRectangles are used
to represent process step for calculations
• Diamonds are used to represent decision makingDiamonds are used to represent
decision making
• Directional arrows are used to represent the flow of control from one part of
Directional arrows are used to represent the flow of control from one part of
flowchart to flowchart to anotheranother
Question 14
Question 14
omplete algorithm after adding other options is as follows
omplete algorithm after adding other options is as follows
a. Wake upWake up
b. Brush teethBrush teeth
c. Eat breakfastEat breakfast
d. Get readyGet ready
e. Take lunch boxTake lunch box
f. Walk to bus stopWalk to bus stop
g. Take busTake bus
h. Get off the busGet off the bus
i. Reach school or collegeReach school or college
Question 15
Question 15
Declare N and F as
Declare N and F as integer variable.integer variable.
1. Initialize F=1.Initialize F=1.
2. Enter the value of N.Enter the value of N.
3. Check whether N>0, if not then F=1.Check whether N>0, if not then F=1.
4. If yes then, F=F*N.If yes then, F=F*N.
5. Decrease the value of N by 1.Decrease the value of N by 1.
6. Repeat step 4 and 5 until N=0.Repeat step 4 and 5 until N=0.
7. Now print the value of F.Now print the value of F.
Question 16
Question 16
The flowchart explains the process flow of as
The flowchart explains the process flow of asking the user to input a number. The
number is divided king the user to input a number. The number is divided into
digits and each digit is cubed and summed. The sum of the cube of the digits is
then compared into digits and each digit is cubed and summed. The sum of the cube
of the digits is then compared to the number given by the user. And depending upon
the result of the comparison the number is to the number given by the user. And
depending upon the result of the comparison the number is then dethen determined as
Armstrong number or not.termined as Armstrong number or not.
Question 17
Question 17
Verifying for 5, 5 is less than 9 so the output is Single Digit which is correct
Verifying for 5, 5 is less than 9 so the output is Single Digit which is correct
1. Verifying for 9, 9 is not less than 9 so we compare it with 99. 9 is less than
99 so the output Verifying for 9, 9 is not less than 9 so we compare it with 99. 9
is less than 99 so the output is Doubleis Double--Digit which is incorDigit which
is incorrectrect
2. Verifying for 47, 47 is not less than 9 so compare it with 99. 47 us less than
99 so the output Verifying for 47, 47 is not less than 9 so compare it with 99. 47
us less than 99 so the output is doubleis double--digit which is correctdigit which
is correct
3. Verifying for 99, 99is not less than 9 so we compare it with 99. 99 is not less
than 99 so the Verifying for 99, 99is not less than 9 so we compare it with 99. 99
is not less than 99 so the output is Big which is incooutput is Big which is
incorrect.rrect.
4. Verifying for 100, 100 s not less than 9 so we compare it with 99. 100 is not
less than 99 so Verifying for 100, 100 s not less than 9 so we compare it with 99.
100 is not less than 99 so the output is Big which is correct.the output is Big
which is correct.
5. Verifying for 200, 200 s not less than 9 so we compare it with 99. 200 is not
less than 99 so Verifying for 200, 200 s not less than 9 so we compare it with 99.
200 is not less than 99 so the output is Big which ithe output is Big which is
correct.s correct.
The above algorithm is incorrect in the case of number 9 and number 99 so we have
to modify the
The above algorithm is incorrect in the case of number 9 and number 99 so we have
to modify the algorithm as follows.algorithm as follows.
INPUT number
INPUT number
IF number<= 9
IF number<= 9
“single digit”
“single digit”
ELSE IF number <= 99
ELSE IF number <= 99
“double digit”
“double digit”
ELSE
ELSE
“big
“big
Question 18 A
Question 18 A
The algorithm will
The algorithm will fail for the value 0. Since the if a condition is true if the
value of the NUMBER fail for the value 0. Since the if a condition is true if the
value of the NUMBER is 0 it will accept the input. But the algorithm is supposed to
accept numbers between 1 and 100 is 0 it will accept the input. But the algorithm
is supposed to accept numbers between 1 and 100 only.only.
Question 18 B
Question 18 B
The algorithm can be improved as follows:
The algorithm can be improved as follows:
INPUT NUMBER
INPUT NUMBER
I
If (0 < NUMBER) AND (NUMBER <= 100)f (0 < NUMBER) AND (NUMBER <= 100)
ACCEPT
ACCEPT
ELSE
ELSE
REJECT
REJECT