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

pseudocode

The document contains pseudo code solutions for various programming problems, including checking if a number is even or odd, finding the largest of two numbers, calculating grades, and simulating games. Each problem is presented with a clear description and corresponding pseudo code. The problems cover a range of topics such as loops, conditionals, and calculations relevant to programming logic.

Uploaded by

2022-3-60-096
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)
2 views

pseudocode

The document contains pseudo code solutions for various programming problems, including checking if a number is even or odd, finding the largest of two numbers, calculating grades, and simulating games. Each problem is presented with a clear description and corresponding pseudo code. The problems cover a range of topics such as loops, conditionals, and calculations relevant to programming logic.

Uploaded by

2022-3-60-096
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/ 9

1.

Even or Odd

Problem: Write a pseudo code to check if a given number is even or odd.

Pseudo Code:

START
INPUT number
IF number % 2 == 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
ENDIF
END

2. Find the Largest Number

Problem: Write a pseudo code to find the largest of two numbers.

Pseudo Code:

START
INPUT num1, num2
IF num1 > num2 THEN
PRINT num1 + " is larger"
ELSE
PRINT num2 + " is larger"
ENDIF
END

3. Grade Calculation Using Case

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

4. Sum of First 10 Numbers Using For Loop

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

5. Factorial Calculation Using While Loop

Problem: Write a pseudo code to calculate the factorial of a number.

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

7. Multiplication Table Using For Loop

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

8. Countdown Using Repeat Until Loop

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

9. Check Positive or Negative

Problem: Write a pseudo code to check if a number is positive, negative, or zero.

Pseudo Code:

START
INPUT number
IF number > 0 THEN
PRINT "Positive"
ELSE IF number < 0 THEN
PRINT "Negative"
ELSE
PRINT "Zero"
ENDIF
END

10. Sum of Even Numbers Using While Loop

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

11. Production House Cost Calculation


Problem: A production house produces 50 items each day. There are 3 types of items: Type A,
Type B, and Type C. Each type has two costs (Cost 1 and Cost 2). For Type A, multiply Cost 1
by 2 and Cost 2 by 3. For Type B, multiply both costs by 5. For Type C, add Cost 1 and Cost 2.
Calculate and display the total production cost for all 50 items using a for loop and if-else
statements.

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

12. Student Pass or Fail

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

14. Temperature Converter

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

15. ATM Withdrawal Simulation


Problem: Write a pseudo code for an ATM machine that allows a user to withdraw an amount.
The ATM has $100, $50, and $20 bills. The machine must minimize the number of bills used.
For example, to withdraw $270, the machine should give two $100 bills, one $50 bill, and one
$20 bill.

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

16. Discount Calculator

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

17. Car Fuel Efficiency

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

18. Average Marks of 5 Subjects

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

19. Number Guessing Game

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

20. Square and Cube of a Number

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

You might also like