[go: up one dir, main page]

0% found this document useful (0 votes)
4 views5 pages

Chapter - 4 Introduction To Problem Solving

The document provides pseudocode and algorithms for various programming problems, including division, games, loops, calculations, and conditionals. It covers topics such as finding the greatest number, calculating water bills, and classifying numbers. Additionally, it includes flowchart symbols and improved algorithms for specific tasks.

Uploaded by

Roli Devi
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)
4 views5 pages

Chapter - 4 Introduction To Problem Solving

The document provides pseudocode and algorithms for various programming problems, including division, games, loops, calculations, and conditionals. It covers topics such as finding the greatest number, calculating water bills, and classifying numbers. Additionally, it includes flowchart symbols and improved algorithms for specific tasks.

Uploaded by

Roli Devi
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/ 5

Computer Science (XI)

Chap-4 Introduction to Problem Solving

1. Pseudocode to divide one number by another and display quotient

START
INPUT num1
INPUT num2
IF num2 ≠ 0 THEN
quotient ← num1 / num2
PRINT quotient
ELSE
PRINT "Division by zero not allowed"
END IF
END

2. Coin flip game to decide who gets the cake

START
player1_score ← 0
player2_score ← 0
REPEAT
INPUT flip_result // 1 for player1, 2 for player2
IF flip_result = 1 THEN
player1_score ← player1_score + 1
ELSE IF flip_result = 2 THEN
player2_score ← player2_score + 1
END IF
UNTIL player1_score = 3 OR player2_score = 3

IF player1_score = 3 THEN
PRINT "Player 1 wins the cake"
ELSE
PRINT "Player 2 wins the cake"
END

3. Print multiples of 5 between 10 and 25

FOR i FROM 10 TO 25 STEP 1


IF i MOD 5 = 0 THEN
PRINT i
END IF
END FOR

4. Example of a fixed loop (e.g., print numbers 1 to 5)

FOR i FROM 1 TO 5
PRINT i
END FOR
5. Algorithm to collect ₹200 from relatives

START
total ← 0
WHILE total < 200
INPUT amount_given
total ← total + amount_given
END WHILE
PRINT "Collected total of ₹", total
END

6. Pseudocode to print bill with 5% GST

START
INPUT price
INPUT quantity
total ← price × quantity
gst ← total × 0.05
final_bill ← total + gst
PRINT "Total before GST:", total
PRINT "GST (5%):", gst
PRINT "Final Bill:", final_bill
END

7. Pseudocode to calculate total and percentage of marks

START
INPUT cs_marks
INPUT math_marks
INPUT physics_marks
total ← cs_marks + math_marks + physics_marks
percentage ← total / 3
PRINT "Total Marks:", total
PRINT "Percentage:", percentage
END

8. Algorithm to find the greatest among two numbers

START
INPUT num1
INPUT num2
IF num1 > num2 THEN
PRINT num1, "is greater"
ELSE
PRINT num2, "is greater"
END

9. Color code based on number input

START
INPUT number
IF number >= 5 AND number < 15 THEN
PRINT "GREEN"
ELSE IF number >= 15 AND number < 25 THEN
PRINT "BLUE"
ELSE IF number >= 25 AND number < 35 THEN
PRINT "ORANGE"
ELSE
PRINT "ALL COLOURS ARE BEAUTIFUL"
END

10. Algorithm to find the largest and smallest among 4 numbers

START
INPUT a, b, c, d
largest ← a
smallest ← a

IF b > largest THEN largest ← b


IF c > largest THEN largest ← c
IF d > largest THEN largest ← d

IF b < smallest THEN smallest ← b


IF c < smallest THEN smallest ← c
IF d < smallest THEN smallest ← d

PRINT "Largest:", largest


PRINT "Smallest:", smallest
END

11. Water bill calculation

START
INPUT units
meter_charge ← 75
bill ← 0

IF units <= 100 THEN


bill ← units × 5
ELSE IF units <= 250 THEN
bill ← 100 × 5 + (units - 100) × 10
ELSE
bill ← 100 × 5 + 150 × 10 + (units - 250) × 20
END IF

total_bill ← bill + meter_charge


PRINT "Total Water Bill:", total_bill
END

12. What are conditionals?

Answer:
Conditionals are programming statements used to perform different actions based on different
conditions. They are required when a decision needs to be made in a program using IF, ELSE
IF, and ELSE statements.

13. Match the flowchart symbols

Start/Stop of the Process → Oval


Process Step → Rectangle
Decision Making → Diamond
Flow of Control → Arrow

14. Improved Reach_School_Algorithm

START
Wake up
Get ready
Take lunch box

INPUT transport (bus, car, cycle, walk)


IF transport = "bus" THEN
Take bus
Get off bus
ELSE IF transport = "car" THEN
Get in car
Reach school by car
ELSE IF transport = "cycle" THEN
Ride cycle to school
ELSE IF transport = "walk" THEN
Walk to school
END IF

Reach school
END

15. Pseudocode for factorial

START
INPUT n
factorial ← 1
FOR i FROM 1 TO n
factorial ← factorial × i
END FOR
PRINT "Factorial of", n, "is", factorial
END

16. Flowchart for Armstrong Number

(Textual Pseudocode since drawing not supported)

START
INPUT number
original ← number
sum ← 0
WHILE number > 0
digit ← number MOD 10
sum ← sum + (digit × digit × digit)
number ← number DIV 10
END WHILE
IF sum = original THEN
PRINT "Armstrong Number"
ELSE
PRINT "Not an Armstrong Number"
END

17. Classify Numbers Algorithm (Corrected)

START
INPUT number
IF number >= 0 AND number <= 9 THEN
PRINT "Single Digit"
ELSE IF number >= 10 AND number <= 99 THEN
PRINT "Double Digit"
ELSE
PRINT "Big"
END

Test with:
5 → Single Digit
9 → Single Digit
47 → Double Digit
99 → Double Digit
100, 200 → Big ✅

18. Accept only numbers 1 to 100

a) On what values will this fail?


It will accept 0 (which should not be allowed), and fail for negatives or above 100.

b) Improved Algorithm

START
INPUT number
IF number ≥ 1 AND number ≤ 100 THEN
PRINT "ACCEPT"
ELSE
PRINT "REJECT"
END

You might also like