wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

BSTECHM- MIDTERM EXAM

Total questions: 50

Worksheet time: 38mins

Name
Class
Date
1.

In the sequence of steps used in program development, what step comes right after “Testing the algorithm for correctness”?

a)

Define the problem

b)

Develop algorithm

c)

Outline the solution

d)

Code the algorithm

2.

Which pair of steps in the Program Development process primarily focuses on planning before any code is written?

a)

Code the Algorithm and Test the Program.

b)

Document the Program and Maintain the Program

c)

Test the Algorithm for Correctness and Debug the Program.

d)

Define the Problem and Design the Algorithm.

3.

Which step follows after “coding the algorithm” in program development?

a)

Define the Problem

b)

Compile the Program

c)

Test the Algorithm for Correctness

d)

Outline the Solution

4.

If a user is employing a Flowchart to detail their solution, which program development step are they currently performing or solidifying?

a)

Develop an algorithm        

b)

Design the Algorithm

c)

Code the Algorithm

d)

Test the Program

5.

You have a program that does not run because of syntax errors. Which step helps identify and fix these errors?

a)

Compile the Program        

b)

Test the Algorithm  

c)

Run the Program

d)

Document the Program

6.

Which statement best explains the difference between “compiling” and “running a program”?

a)

Compiling checks logic; running writes code.

b)

Compiling translates code; running executes the translated code

c)

Running translates the code; compiling executes it

d)

They are both the same

7.

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?

a)

The first test checks the code for syntax errors, while the second test checks the algorithm's logic using actual code.

b)

The first test is done before the algorithm is written, while the second is done after coding is complete.

c)

The first test checks the algorithm's logic using pseudocode or flowcharts, while the second tests the actual working program for errors and performance.

d)

There is no difference; both steps involve testing the same thing in the same way.

8.

If a program compiles without errors but produces incorrect output, which program development step should be revisited?

a)

Define the Problem

b)

Test the Algorithm for Correctness

c)

Compile the Program

d)

Document the Program

9.

You test a program with several inputs and find inconsistent results. What should you evaluate first?

a)

Your hardware        

b)

The flowchart Tool

c)

The file system

d)

The algorithm logic

10.

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?

a)

It shows that the program needs to be rewritten in another language.

b)

It shows that maintenance is necessary to improve readability.

c)

It shows that maintenance is essential to fix bugs and adapt to changing requirements.

d)

It shows that the code should be shortened to improve efficiency.

11.

Which data type is used to store a single character?

a)

char

b)

string

c)

keyword

d)

text

12.

Which of the following is a correct variable declaration in C?

a)

int x = 10;       

b)

float 2x;

c)

int x = "10";

d)

char = 'A';

13.

Which escape code represents a tab space?

a)

\n        

b)

\r

c)

\t

d)

\b

14.

Which format specifier is used to display a float value?

a)

%f       

b)

%c

c)

%d      

d)

%s

15.

What will \n do when used in printf()?

a)

Backspace

b)

Tab space

c)

New line

d)

Null character

16.

What is the purpose of #include <stdio.h> in a C program?

a)

To define variables

b)

To end program

c)

To start main function

d)

To import standard input-output functions

17.

What will be the output of the following C code?

#include <stdio.h>

int main() {

printf("Hello, World!");

return 0;}

a)

Hello, World!

b)

“Hello, world”!

c)

hello, World!

d)

Hello World!

18.

Modify the given code to produce the correct output based on the specified requirements. What will be the result?

a)

x        

b)

%d

c)

5

d)

Error

19.

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);

a)

10 5

b)

10 5.5

c)

10.0 5.5

d)

Error

20.

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;}

a)

%f is incorrect for an integer        

b)

printf cannot print integers 

c)

a is not initialized

d)

main function should return float

21.

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.

a)

b)

c)

d)

22.

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.

a)

b)

c)

d)

23.

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;}

a)

Remove scanf() line

b)

Add & to printf

c)

Declare num as float

d)

Change %f to %d in scanf()

24.

After executing the following code, what output will be displayed on the screen?

int a = 5;

printf("%d", ++a);

a)

5

b)

 4

c)

6

d)

error

25.

What is the output of printf("%d", 5 > 2);?

a)

  1      

b)

2

c)

5

d)

0

26.

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);

a)

5 10

b)

6 10

c)

6 12

d)

5 12

27.

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);

a)

2       

b)

5       

c)

15

d)

10

28.

Which of the following C programs correctly determines the highest order set bit (from left to right) in a given integer?

a)

b)

c)

d)

29.

Which of the following C programs correctly converts a decimal number to its binary equivalent using bitwise operators?

a)

b)

c)

d)

30.

Identify which of the following is an invalid assignment in C.

a)

a = 5; 

b)

5 = a;

c)

x = y = 0;

d)

total = x + y;

31.

Evaluate: 5 & 3 (in binary: 0101 & 0011)

a)

3       

b)

 5

c)

7

d)

1

32.

Analyze the expression: What is the final value of x?

int x = 8 / 2 * (2 + 2);

a)

8       

b)

16

c)

 4      

d)

 6

33.

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);

a)

14      

b)

13

c)

10

d)

15

34.

Identify what will be the output of this code?

int x = 3;

if (x == 3)

    printf("Equal");

else

    printf("Not Equal");

a)

Not Equal       

b)

No output

c)

Error

d)

Equal

35.

Determine what is the output of this statement?

if (5 > 10)

    printf("True");

a)

True    

b)

 False

c)

Nothing is printed

d)

greater than

36.

Identify the correct output:

int a = 2, b = 4;

if (a * 2 == b)

    printf("Equal");

else

    printf("Not Equal");

a)

Equal

b)

Not Equal

c)

 Error

d)

4

37.

Given that x = 10 and y = 20, determine the output of the following statement:

(x > y) ? printf("X") : printf("Y");

a)

 X      

b)

 Y

c)

Error

d)

X>Y

38.

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");

a)

X

b)

Y

c)

Nothing

d)

Error

39.

Evaluate this code, what is the result?

int x=5;

(x>0)?printf("Positive"):printf("Negative");

a)

Positive

b)

Negative

c)

Error

d)

 0

40.

Which of the following C programs correctly determines in which quadrant a coordinate point (x, y) lies?

a)

b)

c)

d)

41.

Which of the following C programs correctly calculates the total, percentage, and division of a student based on marks in three subjects?

a)

b)

c)

d)

42.

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

a)

b)

c)

d)

43.

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;

}

a)

Change if(a = b) to if(a == b)

b)

Replace if(a = b) with if(a != b)

c)

Replace scanf("%d %d", &a, &b); with scanf("%d", &a, &b);

d)

Add a semicolon after if(a == b);

44.

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;

}

a)

The second condition should use || instead of &&

b)

The first condition if(height > 150.0) should be if(height < 150.0)

c)

The last else statement should include a condition

d)

The comparison operators should be replaced with assignment operators (=)

45.

Which of the following C programs correctly displays the cube of numbers up to a given integer?

a)

b)

c)

d)

46.

Which of the following C programs correctly finds the number and sum of all integers between 100 and 200 that are divisible by 9?

a)

b)

c)

d)

47.

Which of the following C programs correctly prints all natural numbers in reverse from 150 to 1 using a for loop?

a)

b)

c)

d)

48.

Determine what is the output:

int choice = 4;

switch(choice) {

    case 1: printf("Add");

    case 2: printf("Subtract");

    default: printf("Invalid");

}

a)

AddSubtractInvalid

b)

Invalid

c)

SubtractInvalid

d)

a.    Addinvalid

49.

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");

      }

 

a)

                

***

***

***

b)

*

*

*

c)

***

**

*

d)

*

**

***

50.

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");

   }

a)

             1                  

22

333

b)

1

23

123

c)

1

12

123

d)

3

33

333