Вы находитесь на странице: 1из 2

Introduction to Computer Science

Branching questions

You often need to convert Rupees into coins of 5, 2, and 1 as your younger brother often asks
you for some money in coins, to put them in his moneybox. Your brother can ask you for any
amount of money like 33 Rupees or 54 Rupees etc. So you need to develop a program, which
takes the amount of money in terms of rupees and then computes a mix of coins of 5, 2 and 1
against that money. Remember that you may not always have enough coins. So the program
should be able to covert the money into the coins available. For example, if you dont have the
coins of 5-rupees, then for 7 rupees the program should compute a mix of 2-rupees and 1-rupee
coins, i.e. 3 coins of 2-rupees and one coin of 1-rupee. For this program, assume that you always
have enough number of 1-rupee coins against any amount of money. The program should also
take as input the number of 5-rupees and 2-rupees coins available. The program should compute
the amount of money in terms of numbers of 5-rupees coins, 2-rupees coins and 1-rupee coins.
Write pseudocode for the program
Exercise 1:
The player makes three rolls of the dice. The player wins if the three rolls of the dice form the
following sequence:
First roll is a 5 or 6
Second roll is a 3 or 4
Third roll is a 1 or 2
Write a pseudo code for this problem that takes as input three values (rolls of dice) and prints
You won if the three values (rolls of dice) follow the above sequence and You lost otherwise.
Exercise 2:
Suppose you are designing a game of tic tac toe. The user is x and the computer is o.
Suppose during the game the following situation (on the left) is encountered:
O
o

X
x
x

a
d
g

B
E
H

c
f
i

Its the users turn to play (the o). Write pseudo code to take input from the user as to which
box the user should enter the o. The cells are labeled from a to i' as shown above on the
right. The user will enter the cell label where to put an o. After the user gives an input, its the
computers turn to play. Your pseudo-code should then be able to decide which cell the
computer has to put an x. As output you have to print who won the game or if it was a draw.
(Consider the user enters a valid box label i.e. not any box label that is already taken).

Exercise 3:
Write pseudo code for a program that takes input marks and Print the message accordingly. It
will display following messages depend upon the marks.
Total Marks
< 50
>50 & <60
>60 & < 70
>70 & < 80
>80 & <= 100

Message
Fail
Grade D
Grade C
Grade B
Grade A

Exercise 4:
Write a pseudo code that takes a number and tells whether the number entered is
a) Either even or odd
b) Either positive or negative
c) Either Zero or Not Zero
Note: For example if given number is 2 then you should display The number is even and
positive and not Zero
Exercise 5:
As you are studying here in the university, you need to buy notebooks in every semester. For this,
your parents give you some money. You buy the notebooks from the photocopier shop at the
campus. The photocopier has given a good offer to new students that if you get more than 7
notebooks at a time, you will get one notebook free for every 3 notebooks. You should spend all
the money on the notebooks and if you get extra notebooks, you should keep them for the next
semester. You need to find out whether you can buy enough books in the available money, or not.
Make a program that helps you in this calculation. The program should take as input the amount
of money you have for notebooks, the number of notebooks you need for this semester, and the
cost of one notebook. The program should then tell how many notebooks you can buy from the
available money, including the number of notebooks that you get free in the offer. If the number
of notebooks you can buy is not enough for a semester and you need more notebooks, then the
program should tell how much more money you need to get more books. (Remember that the
offer by the photocopier does not remain valid when you buy more books second time).
Otherwise if the number of notebooks you can buy are enough for the semester or are more than
enough, then the program should tell how many extra notebooks you are getting to keep for the
next semester.
Write pseudocode for the program.

Вам также может понравиться