NEW
Font size
WorksheetsBSTECHM- MIDTERM EXAM
Total questions: 50
Worksheet time: 38mins
In the sequence of steps used in program development, what step comes right after “Testing the algorithm for correctness”?
Define the problem
Develop algorithm
Outline the solution
Code the algorithm
Which pair of steps in the Program Development process primarily focuses on planning before any code is written?
Code the Algorithm and Test the Program.
Document the Program and Maintain the Program
Test the Algorithm for Correctness and Debug the Program.
Define the Problem and Design the Algorithm.
Which step follows after “coding the algorithm” in program development?
Define the Problem
Compile the Program
Test the Algorithm for Correctness
Outline the Solution
If a user is employing a Flowchart to detail their solution, which program development step are they currently performing or solidifying?
Develop an algorithm
Design the Algorithm
Code the Algorithm
Test the Program
You have a program that does not run because of syntax errors. Which step helps identify and fix these errors?
Compile the Program
Test the Algorithm
Run the Program
Document the Program
Which statement best explains the difference between “compiling” and “running a program”?
Compiling checks logic; running writes code.
Compiling translates code; running executes the translated code
Running translates the code; compiling executes it
They are both the same
How does the test in the step "Test, Document, and Maintain the Program" differ from the "Test the Algorithm for Correctness" step earlier in the program development process?
The first test checks the code for syntax errors, while the second test checks the algorithm's logic using actual code.
The first test is done before the algorithm is written, while the second is done after coding is complete.
The first test checks the algorithm's logic using pseudocode or flowcharts, while the second tests the actual working program for errors and performance.
There is no difference; both steps involve testing the same thing in the same way.
If a program compiles without errors but produces incorrect output, which program development step should be revisited?
Define the Problem
Test the Algorithm for Correctness
Compile the Program
Document the Program
You test a program with several inputs and find inconsistent results. What should you evaluate first?
Your hardware
The flowchart Tool
The file system
The algorithm logic
A program has been deployed and users have started reporting errors and requesting new features. What does this situation indicate about the importance of maintaining the program?
It shows that the program needs to be rewritten in another language.
It shows that maintenance is necessary to improve readability.
It shows that maintenance is essential to fix bugs and adapt to changing requirements.
It shows that the code should be shortened to improve efficiency.
Which data type is used to store a single character?
char
string
keyword
text
Which of the following is a correct variable declaration in C?
int x = 10;
float 2x;
int x = "10";
char = 'A';
Which escape code represents a tab space?
\n
\r
\t
\b
Which format specifier is used to display a float value?
%f
%c
%d
%s
What will \n do when used in printf()?
Backspace
Tab space
New line
Null character
What is the purpose of #include <stdio.h> in a C program?
To define variables
To end program
To start main function
To import standard input-output functions
What will be the output of the following C code?
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;}
Hello, World!
“Hello, world”!
hello, World!
Hello World!
Modify the given code to produce the correct output based on the specified requirements. What will be the result?
x
%d
5
Error
Execute the given code to produce the correct output. What will be the expected output of the following code? (int a = 10; float b = 5.5; printf("%d %f", a, b);
10 5
10 5.5
10.0 5.5
Error
Which of the following best explains why the following code produces incorrect output?
#include <stdio.h>
int main() {
int a = 5;
printf("a = %f", a);
return 0;}
%f is incorrect for an integer
printf cannot print integers
a is not initialized
main function should return float
Analyze the following C programs and identify which one correctly reads a user's forename, surname, and year of birth, then displays them sequentially in a single line.
Analyze the following C programs and determine which one correctly implements the perimeter calculation for a rectangle using user input for its height and width.
Evaluate the following code. What is the best way to fix it?
#include <stdio.h>
int main() {
int num;
scanf("%f", &num);
printf("You entered: %d", num);
return 0;}
Remove scanf() line
Add & to printf
Declare num as float
Change %f to %d in scanf()
After executing the following code, what output will be displayed on the screen?
int a = 5;
printf("%d", ++a);
5
4
6
error
What is the output of printf("%d", 5 > 2);?
1
2
5
0
After executing the following code segment, what values will be displayed for a and b?
int a = 5, b = ++a * 2;
printf("%d %d", a, b);
5 10
6 10
6 12
5 12
Use your knowledge of arithmetic operations in C to determine the output of the following code segment. What value will be printed for z?
int x = 5, y = 10, z;
z = x * y / x;
printf("%d", z);
2
5
15
10
Which of the following C programs correctly determines the highest order set bit (from left to right) in a given integer?
Which of the following C programs correctly converts a decimal number to its binary equivalent using bitwise operators?
Identify which of the following is an invalid assignment in C.
a = 5;
5 = a;
x = y = 0;
total = x + y;
Evaluate: 5 & 3 (in binary: 0101 & 0011)
3
5
7
1
Analyze the expression: What is the final value of x?
int x = 8 / 2 * (2 + 2);
8
16
4
6
Analyze the order of operations and increment effects in the following code. Which option correctly explains and gives the final value of c?
int a = 2, b = 3, c;
c = a++ + ++b * a;
printf("%d", c);
14
13
10
15
Identify what will be the output of this code?
int x = 3;
if (x == 3)
printf("Equal");
else
printf("Not Equal");
Not Equal
No output
Error
Equal
Determine what is the output of this statement?
if (5 > 10)
printf("True");
True
False
Nothing is printed
greater than
Identify the correct output:
int a = 2, b = 4;
if (a * 2 == b)
printf("Equal");
else
printf("Not Equal");
Equal
Not Equal
Error
4
Given that x = 10 and y = 20, determine the output of the following statement:
(x > y) ? printf("X") : printf("Y");
X
Y
Error
X>Y
Identify what is the output of the given code?
int a=1, b=2, c=3;
if (a > b)
if (b > c)
printf("X");
else
printf("Y");
X
Y
Nothing
Error
Evaluate this code, what is the result?
int x=5;
(x>0)?printf("Positive"):printf("Negative");
Positive
Negative
Error
0
Which of the following C programs correctly determines in which quadrant a coordinate point (x, y) lies?
Which of the following C programs correctly calculates the total, percentage, and division of a student based on marks in three subjects?
Write a C program to read temperature in centigrade and display a suitable message according to the temperature state below:
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot Temp >=40 then Its Very Hot
Analyze the code below and determine which modification will make the program correctly display “Both numbers are equal” when the user enters 7 and 7.
#include <stdio.h>
int main() {
int a, b;
printf("Enter two integers: ");
scanf("%d %d", &a, &b);
if(a = b)
printf("Both numbers are equal");
else
printf("Numbers are not equal");
return 0;
}
Change if(a = b) to if(a == b)
Replace if(a = b) with if(a != b)
Replace scanf("%d %d", &a, &b); with scanf("%d", &a, &b);
Add a semicolon after if(a == b);
Analyze the code and identify which logical error causes the problem.
#include <stdio.h>
int main() {
float height;
printf("Enter height in centimeters: ");
scanf("%f", &height);
if(height > 150.0)
printf("The person is Short.");
else if(height >= 150.0 && height < 180.0)
printf("The person is of Average height.");
else
printf("The person is Tall.");
return 0;
}
The second condition should use || instead of &&
The first condition if(height > 150.0) should be if(height < 150.0)
The last else statement should include a condition
The comparison operators should be replaced with assignment operators (=)
Which of the following C programs correctly displays the cube of numbers up to a given integer?
Which of the following C programs correctly finds the number and sum of all integers between 100 and 200 that are divisible by 9?
Which of the following C programs correctly prints all natural numbers in reverse from 150 to 1 using a for loop?
Determine what is the output:
int choice = 4;
switch(choice) {
case 1: printf("Add");
case 2: printf("Subtract");
default: printf("Invalid");
}
AddSubtractInvalid
Invalid
SubtractInvalid
a. Addinvalid
What will be the output of the following code?
for(int i=1; i<=3; i++){
for(int j=1; j<=i; j++){
printf("*");
}
printf("\n");
}
***
***
***
*
*
*
***
**
*
*
**
***
What will be the output of the following code?
for(int i=1; i<=3; i++){
for(int j=1; j<=i; j++){
printf("%d", i);
}
printf("\n");
}
1
22
333
1
23
123
1
12
123
3
33
333
