Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
W.A.P. in C that acts as a guessing game in which the user has eight tries to gu
ess a randomly generated number within 100. Theprogram will tell the user each t
ime whether he guessed high or low. The user WINS the game when the number guess
ed is same asrandomly generated number.
7.
W.A.P. to determine how much money is in a piggy bank that contains several 50 p
aise coins, 25 paise coins, 20 paise coins, 10 paisecoins and 5 paise coins. Use
the following values to test your program : Five 50 paise coins, Three 25 paise
coins, Two 20 paise coins,One 10 paise coin and Fifteen 5 paise coins. (Answer
: Rs. 4.50)
8.
W.A.P. in C to determine how many of the characters are vowels and how many are
consonants in a given line of text. Also terminatethe string when the input char
acter encountered is other than the alphabets(a-z or A-Z) and Blank spaces.[Hint
:(a) When the input string is 'C FOR SWIMMERS, TEST YOUR C PROGRAMMING STRENGTHS
'. Consider the string 'C FORSWIMMERS' only Because ',' is encountered. (b) When
the input string is 'Y2K PROBLEM'. Consider the character 'Y' only Becausethe '
2' is encountered.]
9.
Write a program to play a game of marbles. The game starts with 32 marbles and t
wo players. Each player must take 1, 2 or 3 marbleson their turn. Turns go back
and forth between the two players. The winner is the person who takes the last m
arble. Your programshould prompt each player with a message that states the curr
ent number of marbles and asks them how many they'd like to take.Continue until
there is a winner. Then your program should print out the winner (either player
#1 or player #2.) (Incidentally, if bothplayers play optimally, who always wins?
What is their strategy?)
10.
Write a function that takes in the coefficients a (not 0), b, and c (all doubles
) to a quadratic equation and returns the smaller of the tworoots (a double) as
the result. You may assume that the roots of the quadratic are real. The formula
for the roots of a quadratic is given below
x=-b+-root(b*b-4ac)/2a