How many days of rest do you need to recover from jet lag? The International Civil Avaiation Organization has a fomula for this:
The number of days you need to recover is:
days of recovery = (Hours/2 + (Zones-3) + Depart + Arrive)/10
For example, say that you are flying from New York Kennedy Airport to London Heathrow. Your flight leaves at 7AM (New York time) and arrives at 7PM (London time).
days of recovery = (7/2 + (4-3) + 5 + 0)/10 = (3.5 + 1 + 5 + 0)/10 = 9.5/10 = 0.95 days
Write a program that asks the user for the number of hours of travel, the number of time zones crossed, the departure time, and the arrival time and then calculates the number of days needed for recovery. Let the user enter time using a 24 hour clock (so 6PM is 18).
(Formula from Darrell Huff, How to Figure It, Norton, 1996.
Write a program that adds up the squares and adds up the cubes of integers from 1 to N, where N is entered by the user:
Upper Limit: 5 The sum of Squares is 55 The sum of Cubes is 225
Do this by using just one loop that generates the integers. Of course, if you really needed to calculate these sums you would use the appropriate formulas:
12 + 22 + 32 + ... + n2 = n(n+1)(2n+1)/6
13 + 23 + 33 + ... + n3 = n2(n+1)2/4
Add these formulas to your program and print out their results as well as that of the explicit summations.
Click here to go back to the main menu.
Write a program that computes XN
where X is a floating point number and N is a positive integer.
The program informs the user that N must be positive if
the user enters a negative value.
Of course,
XN = X * X * X * ... * X
--------------------
N times
The user dialog will look something like this:
Enter X 1.3 Enter N 5 1.3 raised to the power 5 is: 3.71293 ------- Enter X 5.6 Enter N -3 N must be a positive integer.
Click here to go back to the main menu.
Write a program that writes a wedge of stars. The user enters the initial number of stars, and the program writes out lines of stars. Each line has one few star than the previous line:
Initial number of stars: 7 ******* ****** ***** **** *** ** *
Click here to go back to the main menu.
Write a program that writes a tree made of stars on the terminal:
*
***
*****
*******
*********
***********
*************
***************
***
***
***
Click here to go back to the main menu.