Number |
Problem |
Language |
Sequence, Arithmetic expressions
|
100
|
Write a program to read a number, calculate its square and print it.
|
|
101
|
Write a program to read distance (real value) in feet, calculate the equivalent distance in meters (meters = feet / 3.28) and print it.
|
|
|
102
|
Write a program to input weight (real value) in pounds, calculate the equivalent weight in kilograms (kilograms = pounds / 2.2) and print it.
|
|
103
|
Write a program to input the number of donuts, calculate the number of donuts left over after packing a dozen donuts in each box, and print it (e.g., given 40 donuts, 4 donuts are left over after packing a dozen donuts in each box).
|
|
|
104
|
Write a program to read the income and expenses of a household, calculate its savings (savings = income - expenses) and print it.
|
|
|
105
|
Write a program to read the length and width of a rectangle, calculate its area and print it.
|
|
|
106
|
Write a program to read the height of a person in inches, calculate it in feet and inches and print it.
|
|
|
if-else statements
|
200
|
Write a program to read distance, a real value, and its unit (miles or kilometers), a character value. The program should calculate and print the equivalent distance in the other unit: if input was in miles, output should be in kilometers and vice versa. Print both the equivalent distance and the other unit, e.g., if input is 1 and m, output should be: Distance is 1.6 kilometers.
|
|
201
|
Write a program to read the number of credits taken by a student and calculate tuition and fees. Tuition is $ 450 per credit, but capped at $ 5000 for 12 or more credits. Fees are $ 30 per credit, but capped at $ 300 for 10 or more credits.
|
|
|
202
|
Write a program to read weight, a real value, and its unit (pounds or kilograms), a character value. The program should calculate and print the corresponding weight in the other unit: if input was in pounds, output should be in kilograms and vice versa. Print both the corresponding weight and the other unit, e.g., if input is 1 and k, output should be: Weight is 2.2 pounds.
|
|
203
|
A prix fixe restaurant charges a flat price per meal: $ 25 per meal for a party of 10 or more diners and $ 30 per meal otherwise. It charges 25% service charge for a party of 6 or more diners and 15% otherwise. Write a program to read the number of diners in the party, and calculate and print the total cost.
|
|
|
204
|
Write a program to read temperature, a real value, and its unit (celsius or fahrenheit), a character value. The program should convert the temperature to the other unit, i.e., convert celsius to fahrenheit and fahrenheit to celsius. It should print the converted temperature and the other unit, e.g., if input is 32 and f, output should be: Temperature is 0 celsius.
|
|
Singly nested if-else statements
|
300
|
Write a program to read wind speed and calculate Fujita tornado scale as follows: 0 for less than 73 mph, 1 for less than 113 mph, 2 for less than 158 mph and 3 otherwise.
|
|
|
301
|
Write a program to read the number of credits taken by a student and calculate the student's status as follows: freshman if credits <= 32, sophomore if credits <= 64, junior if credits <= 96 and senior otherwise.
|
|
|
302
|
Write a program to read the numerical grade of a student and calculate the student's letter grade as follows: A if >= 90, B if >= 80, C if >= 70, D if >= 55 and F otherwise.
|
|
|
303
|
Write a program to read the month as a number and print the corresponding season, computed as follows: January - March is Winter, April - June is Spring, July - September is Summer and October - December is Fall.
|
|
|
304
|
Write a program to read the ph value of a solution (a positive number) and compute its nature as follows: 0 - 6 is acidic, 7 is neutral, 8 - 14 is basic and invalid otherwise.
|
|
Dually nested if-else statements
|
400
|
A bread and breakfast charges based on the month of stay and the number of days for which a room is booked: For January - September stay, $ 99.95 if booked for up to 3 days and $ 89.95 if booked for 4 or more days; For October - December, $ 69.95 if booked for up to 3 days and $ 49.95 otherwise. Write a program to read the month of stay and the number of days booked and calculate the cost per day.
|
|
|
401
|
An online store charges for shipping based on the weight of the package and the days in which it should be delivered: For 1-5 pounds, $ 9.95 if delivered within 2 days and $ 7.95 otherwise; For more than 5 pounds, $ 17.95 if delivered within 2 days and $ 13.95 otherwise. Write a program to read the weight of the package and the number of days in which to be delivered and calculate the cost of shipping.
|
|
|
402
|
A bakery charges for cakes based on the number of cakes ordered and how many days ahead they were ordered: For 1-5 cakes, $ 19.95 per cake if ordered at least 3 days in advance and $ 29.95 otherwise; For more than 5 cakes, $ 15.95 if ordered at least 3 days in advance and $ 26.95 otherwise. Write a program to read the number of cakes and the number of days ordered in advance and calculate the cost per cake.
|
|
|
403
|
Write a program to read gender and age of a driver and calculate insurance premium as follows: $ 195 for male driver under 25, $ 135 for male driver 25 or over, $ 155 for female driver under 25 and $ 105 for female driver 25 or over.
|
|
404
|
Write a program to read the type of patron (child/adult) and the time of the movie and calculate the cost of a movie ticket as follows: $ 9.95 for a child before 5 and $ 13.95 afterwards, $ 14.95 for adults before 5 and $ 19.95 afterwards.
|
|
do-while loops for input validation
|
500
|
Write a program to read the number of credits (minimum 1, maximum 20) and the cost per credit (minimum $ 100, maximum $ 500), compute the tuition and print it.
|
|
|
501
|
Write a program to read the amount of restaurant check (minimum $ 50, maximum $ 500) and the number of diners (minimum 2, maximum 15), compute the cost per diner and print it.
|
|
|
502
|
Write a program to read the number of scoops of ice cream (minimum 1, maximum 4) and the type of ice cream (l for lite, r for regular or o for organic), compute the cost and print it. The price per scoop is $ 1.50 for lite, $ 2.00 for regular and $ 3.00 for organic ice cream.
|
|
503
|
Write a program to read the type of movie tickets (c for child, a for adult or s for senior) and the number of tickets (minimum 1, maximum 12). It should compute the cost of buying the tickets and print it. The price per ticket is $ 9.75 for child, $ 14.75 for adult and $ 12.00 for senior tickets.
|
|