
Lab 8- Exam 2 Review
Authored by Elise Neubarth
Computers
University
Used 9+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
19 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What will be displayed to the screen?
#include <stdio.h>
int main()
{
int num1 =20, num2= 2, num3=3;
int small =num1;
if (small>num2)
{
small =num2;
}
if (small>num3)
{
small=num3;
}
printf("%d", small);
return 0;
}
20
2
3
I don't know
Answer explanation
The code will display 2 onto the screen. The first line of the program is setting a temporary variable called "small" to be the same value as num1. We then compare small to num2. If num2 is less than small, we set small to num2. The program will then go to the second if statement. If num3 is less than small, set small to num3.
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What are the three different kinds of loops?
For loop, while loop, if loop
For loop, while do loop, while loop
For loop, do while loop, while loop
3.
MULTIPLE SELECT QUESTION
45 sec • 1 pt
Which loop is the best to use for the following prompt:
Create a program where a user enters multiple numbers. The program should add up all of the numbers until the user enters 0. Example output:
Enter a number: 1.5
Enter a number: 2.4
Enter a number: -3.4
Enter a number: 4.2
Enter a number: 0
Sum = 4.70
do while loop
while loop
for loop
if loop
Answer explanation
We use a while or a do while loop when we want the program to run as long as a specific condition is met. A do while loop will run one time before the condition is tested. Either loop could be used. However, it is best to use a do while loop because we want the code to run at least one time before we test the condition.
We do not use a for loop in this case because we do not know how many numbers the user wants to enter. Therefore, we do not know how many times the loop needs to run.
4.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Which loop would be best to use for the following prompt?
Create a program that displays the temperature as long as it is sunny outside.
do while
while
for
Answer explanation
A while loop would be better for this prompt because we want the temperature to be displayed only when the weather outside is sunny. We could use a do while loop for this example. However, the do while loop would display the temperature before testing if the condition is met.
We would not use a for loop because we do not know how many times the user will enter a value in.
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Which loop would be best for the following prompt?
Create a program that asks the user to enter multiple numbers and add these numbers together. The user should enter how many values they want to enter. Example output:
How many numbers would you like to enter: 3
Enter number: 23
Enter number: 2
Enter number 5
Sum is 30
do while
while
for
Answer explanation
We will use a for loop since we know how many times the loop needs to run.
You would not use a while or a do while loop because there is not a specific condition that needs to be met.
6.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Write a function prototype for the following prompt:
Create a function that takes in two integers and one character. The function will return a double. The function will add the two integers.
int function (double num1, int num2, num3, char letter);
double function (int num1, int num2, char letter);
char function (double num1, num2, int num3)
{
double sum=num1+num2;
return 'c';
}
double ans=function(2, 4, 'c');
Answer explanation
The function prototype goes at the top of your code. It goes under the #include <stdio.h> and above the main function. The function prototype looks like the following:
returnType function_name (variable).
7.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
How do you declare a pointer?
int numptr
point int numptr
int * numptr
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?