Name: ________________________________________________________
Umail Address: __________________________________@ umail.ucsb.edu
Circle Lab section: 8AM 10AM 11AM noon
Link to Printer Friendly PDF Version
Please write your name only on this page. That allows me to grade your exams without knowing whose exam I am grading.
This exam is closed book, closed notes, closed mouth, cell phone off,
except for:
There are 100 points worth of questions on the exam, and you have 50 minutes to complete the exam.
A hint for allocating your time:
main()
function (incomplete)inToCm()
— this function converts from an integer number of inches into centimeters (possibly with a decimal involved). Add the code that would be necessary, so that this is a complete interactive program that will convert from inches to centimeters. Include code in main that prompts the user for input (using printf/scanf) and then prints the result of a function call to inToCm()
for the user to see the result.
See the extra handout for sample output from this program.
Syntax hints:
// inToCmInteractive.c Answer to a practice exam quesiton // P. Conrad, for CS16 10/16/2009
int main() {
}
double inToCm(int inches) { return inches * 2.54; }
expression |
value |
type |
---|---|---|
3 |
3 |
int double char char * |
0.5 * 0.5 |
0.25 |
int double char char * |
'3' |
int double char char * | |
"3" |
int double char char * | |
1 / 10 |
int double char char * | |
5 / 2.0 |
int double char char * | |
26 % 5 |
int double char char * | |
5 % 2 |
int double char char * | |
1.0 / 10 |
int double char char * | |
1 + 3 * 5 |
int double char char * | |
1 + 1 / 2 |
int double char char * | |
2.0 / 4.0 + 1 |
int double char char * |
Total points: ?
Sample Output from program in question 2:
-bash-3.2$ ./inToCmInteractive
This prorgram converts inches to cm
Please enter inches: 2.54
The answer is: 5.080000
-bash-3.2$ ./inToCmInteractive
This prorgram converts inches to cm
Please enter inches: 1
The answer is: 2.540000
-bash-3.2$ ./inToCmInteractive
This prorgram converts inches to cm
Please enter inches: 2
The answer is: 5.080000
-bash-3.2$ ./inToCmInteractive
This prorgram converts inches to cm
Please enter inches: 36
The answer is: 91.440000
-bash-3.2$