Download Final Practice Answers

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Name__________________________
Final
Sample
Comp Sci 115
Each question is worth 4 points, unless otherwise noted.
Indicate whether each of the following is true or false. Circle the correct answer.
1.
FALSE
2. FALSE
3. TRUE
4.
FALSE
5. TRUE
6. (SKIP) FALSE
7. TRUE
8.
FALSE
9.
bronco
take5
1
10.
A) true
B) true
11.
float gallons;
printf("Gallons pumped?");
scanf("%f", &gallons
12.
The program executes, but there will be a logic error.
13.
****x****y
^^^^2^^^^0
^^^^4^^^^6
^^^^6^^^20
^^^^8^^^42
14.
15.
(SKIP)
(SKIP)
16. (SKIP)
2
17.
A. Argument – base or height
Parameter – b or
B. float area(float, float);
C. area is 6.0
18.
An array is defined by this line in a program:
float numbers [5] = {4.5, 5.5, 6.0, 1.5, -2.0};
A. 0 to 4
B. 1.5
3
19.
Write a program that asks for a list of prices then outputs the total. An
input of -9.99 indicates the end of the list. (8 points)
#include <stdio.h>
#define CUTOFF 0
int main(){
float price;
float total = 0;
printf("Price?");
scanf("%f", &price);
while(price > CUTOFF){
total += price;
printf("Price?");
scanf("%f", &price);
}
printf("Total of the prices is %f.\n", total);
}
20.
A currency exchange is paying 1.0149 Canadian dollars for each US dollar.
Write a C function that takes a US dollar amount and returns the Canadian equivalent.
(8 points)
#include <stdio.h>
#define EX_RATE 1.0149
int main()
{
float usd, cad;
printf("Enter US dollars>");
scanf("%f", &usd);
cad = usd * EX_RATE;
printf("$ %5.2f CA dollars.\n", cad );
return (0);
}
4
5
Related documents