pseudocode
pseudocode
Even or Odd
Pseudo Code:
START
INPUT number
IF number % 2 == 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
ENDIF
END
Pseudo Code:
START
INPUT num1, num2
IF num1 > num2 THEN
PRINT num1 + " is larger"
ELSE
PRINT num2 + " is larger"
ENDIF
END
Problem: Write a pseudo code to assign grades based on marks using a case statement.
Pseudo Code:
START
INPUT marks
CASE marks
90 to 100: PRINT "A"
80 to 89: PRINT "B"
70 to 79: PRINT "C"
60 to 69: PRINT "D"
BELOW 60: PRINT "F"
ENDCASE
END
Problem: Write a pseudo code to calculate the sum of the first 10 natural numbers.
Pseudo Code:
START
sum = 0
FOR i = 1 TO 10 DO
sum = sum + i
ENDFOR
PRINT sum
END
Pseudo Code:
START
INPUT num
factorial = 1
i=1
WHILE i <= num DO
factorial = factorial * i
i=i+1
ENDWHILE
PRINT factorial
END
6. Guess the Number (Do While Loop)
Problem: Write a pseudo code to simulate a "guess the number" game where the user keeps
guessing until they get it right.
Pseudo Code:
START
secret_number = 7
DO
INPUT guess
WHILE guess != secret_number
PRINT "You guessed it right!"
END
Problem: Write a pseudo code to print the multiplication table of a given number.
Pseudo Code:
START
INPUT number
FOR i = 1 TO 10 DO
PRINT number + " * " + i + " = " + (number * i)
ENDFOR
END
Problem: Write a pseudo code for a countdown from 10 to 1 using a repeat until loop.
Pseudo Code:
START
i = 10
REPEAT
PRINT i
i=i-1
UNTIL i == 0
PRINT "Blast Off!"
END
Pseudo Code:
START
INPUT number
IF number > 0 THEN
PRINT "Positive"
ELSE IF number < 0 THEN
PRINT "Negative"
ELSE
PRINT "Zero"
ENDIF
END
Problem: Write a pseudo code to calculate the sum of even numbers between 1 and 20 using a
while loop.
Pseudo Code:
START
sum = 0
i=1
WHILE i <= 20 DO
IF i % 2 == 0 THEN
sum = sum + i
ENDIF
i=i+1
ENDWHILE
PRINT sum
END
Pseudo Code:
START
total_cost = 0
FOR i = 1 TO 50 DO
INPUT item_type, cost1, cost2
IF item_type == "A" THEN
total_cost = total_cost + (cost1 * 2) + (cost2 * 3)
ELSE IF item_type == "B" THEN
total_cost = total_cost + (cost1 * 5) + (cost2 * 5)
ELSE IF item_type == "C" THEN
total_cost = total_cost + (cost1 + cost2)
ENDIF
ENDFOR
PRINT total_cost
END
Problem: A class has 30 students, and each student has three subject marks. Calculate the
total marks for each student and determine if they passed or failed. To pass, a student must
have an average of 40 or more across the three subjects.
Pseudo Code:
START
FOR i = 1 TO 30 DO
INPUT mark1, mark2, mark3
total_marks = mark1 + mark2 + mark3
average = total_marks / 3
IF average >= 40 THEN
PRINT "Pass"
ELSE
PRINT "Fail"
ENDIF
ENDFOR
END
13. Library Fine Calculation
Problem: A library charges a fine based on the number of late days. If the book is returned
within 5 days, there is no fine. For 6 to 10 days late, the fine is $2 per day. Beyond 10 days, the
fine is $5 per day. Write a pseudo code to calculate the fine for 20 books.
Pseudo Code:
START
FOR i = 1 TO 20 DO
INPUT late_days
IF late_days <= 5 THEN
fine = 0
ELSE IF late_days <= 10 THEN
fine = (late_days - 5) * 2
ELSE
fine = (5 * 2) + (late_days - 10) * 5
ENDIF
PRINT fine
ENDFOR
END
Problem: Write a pseudo code to convert temperatures from Celsius to Fahrenheit for 10 cities.
Formula: Fahrenheit = (Celsius * 9/5) + 32.
Pseudo Code:
START
FOR i = 1 TO 10 DO
INPUT celsius
fahrenheit = (celsius * 9 / 5) + 32
PRINT fahrenheit
ENDFOR
END
Pseudo Code:
START
INPUT withdrawal_amount
hundreds = withdrawal_amount / 100
remaining = withdrawal_amount % 100
fifties = remaining / 50
remaining = remaining % 50
twenties = remaining / 20
remaining = remaining % 20
PRINT hundreds + " $100 bills"
PRINT fifties + " $50 bills"
PRINT twenties + " $20 bills"
IF remaining > 0 THEN
PRINT "Cannot withdraw the exact amount"
ENDIF
END
Problem: Write a pseudo code for a store that offers a discount. If the purchase is above $100,
the customer gets a 10% discount. If it's above $200, they get a 20% discount. Calculate and
display the final price for 5 customers.
Pseudo Code:
START
FOR i = 1 TO 5 DO
INPUT purchase_amount
IF purchase_amount > 200 THEN
discount = purchase_amount * 0.2
ELSE IF purchase_amount > 100 THEN
discount = purchase_amount * 0.1
ELSE
discount = 0
ENDIF
final_price = purchase_amount - discount
PRINT final_price
ENDFOR
END
Problem: Write a pseudo code to calculate the fuel efficiency of 10 cars. For each car, input the
total distance traveled and the fuel consumed, then calculate the efficiency using the formula:
Efficiency = Distance / Fuel.
Pseudo Code:
START
FOR i = 1 TO 10 DO
INPUT distance, fuel
efficiency = distance / fuel
PRINT efficiency
ENDFOR
END
Problem: Write a pseudo code to calculate the average marks of 5 subjects for 10 students and
display the result as a grade. Grade A if average >= 80, B if >= 60, C if >= 40, else F.
Pseudo Code:
START
FOR i = 1 TO 10 DO
sum = 0
FOR j = 1 TO 5 DO
INPUT mark
sum = sum + mark
ENDFOR
average = sum / 5
IF average >= 80 THEN
PRINT "A"
ELSE IF average >= 60 THEN
PRINT "B"
ELSE IF average >= 40 THEN
PRINT "C"
ELSE
PRINT "F"
ENDIF
ENDFOR
END
Problem: Write a pseudo code for a number guessing game where the user has to guess a
random number between 1 and 100. After each guess, the program should tell the user if the
guess is too high, too low, or correct.
Pseudo Code:
START
secret_number = 42
DO
INPUT guess
IF guess > secret_number THEN
PRINT "Too high"
ELSE IF guess < secret_number THEN
PRINT "Too low"
ELSE
PRINT "Correct!"
ENDIF
WHILE guess != secret_number
END
Problem: Write a pseudo code to calculate the square and cube of numbers from 1 to 15.
Pseudo Code:
START
FOR i = 1 TO 15 DO
square = i * i
cube = i * i * i
PRINT "Number: " + i + " Square: " + square + " Cube: " + cube
ENDFOR
END