Tutorial 1 Extra: Elementary Programming
MUST READ - Put all the source code and answers into a word file, NAME:
and upload the word file (just ONE Word file! name it with “your
ID+date”, e.g. 202512340001_20250930.doc).
STU ID:
Note: there’s a deadline for uploading.
DATE:
1. Write a program that reads an integer between 0 and 1000 and
adds all the digits in the integer. For example, if an integer is 932,
the sum of all its digits is 14.
Hint: Use the % operator to extract digits, and use the / operator to
remove the extracted digit. For instance, 932 % 10 = 2 and 932 /
10 = 93.
Here is a sample run:
SOURCE CODE (TEXT)
EXECUTION RESULTS (TEXT OR SNAPSHOTS)
THINKING ON THE QUESTION, DISCUSSION AND CONCLUSION
2. Write a program that prompts the user to enter the minutes (e.g.,
1 000 000 000), and displays the number of years and days for the
minutes. For simplicity, assume a year has 365 days. Here is a
sample run:
SOURCE CODE (TEXT)
EXECUTION RESULTS (TEXT OR SNAPSHOTS)
DISCUSSION AND CONCLUSION
3. Body Mass Index (BMI) is a measure of health on weight. It can be
calculated by taking your weight in kilograms and dividing by the
square of your height in meters. Write a program that prompts the
user to enter a weight in pounds and height in inches and displays
the BMI. Note that one pound is 0.45359237 kilograms and one
inch is 0.0254 meters. Here is a sample run:
SOURCE CODE (TEXT)
EXECUTION RESULTS (TEXT OR SNAPSHOTS)
DISCUSSION AND CONCLUSION
4. Write a program that prompts the user to enter the exchange rate
from currency in U.S. dollars to Chinese RMB. Prompt the user to
enter 0 to convert from U.S. dollars to Chinese RMB and 1 to
convert from Chinese RMB and U.S. dollars. Prompt the user to enter
the amount in U.S. dollars or Chinese RMB to convert it to Chinese
RMB or U.S. dollars, respectively. Here are the sample runs:
SOURCE CODE (TEXT)
EXECUTION RESULTS (TEXT OR SNAPSHOTS)
DISCUSSION AND CONCLUSION
5. Write a program that displays all possible combinations for picking
two numbers from integers 1 to 7. Also display the total number of
all combinations.
SOURCE CODE (TEXT)
EXECUTION RESULTS (TEXT OR SNAPSHOTS)
DISCUSSION AND CONCLUSION