0% found this document useful (0 votes)
71 views

Midterm Questions - Answer Sheet

The summary of the document is: 1. It provides a midterm question answer sheet with multiple choice and true/false questions about C programming concepts like variables, operators, loops, conditional statements etc. 2. It includes coding problems with sample inputs/outputs and requires showing the processing steps and outputs. 3. One question asks to find and explain errors in code snippets. 4. Another asks to draw flowcharts for algorithms to check if a number is a "WOW number" and another unspecified problem. 5. The last question asks to write a C program to calculate a phone bill based on number of calls and given call rates.

Uploaded by

aHealthyKidney
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Midterm Questions - Answer Sheet

The summary of the document is: 1. It provides a midterm question answer sheet with multiple choice and true/false questions about C programming concepts like variables, operators, loops, conditional statements etc. 2. It includes coding problems with sample inputs/outputs and requires showing the processing steps and outputs. 3. One question asks to find and explain errors in code snippets. 4. Another asks to draw flowcharts for algorithms to check if a number is a "WOW number" and another unspecified problem. 5. The last question asks to write a C program to calculate a phone bill based on number of calls and given call rates.

Uploaded by

aHealthyKidney
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Midterm Questions - Answer Sheet

1. (15 pts) Fill in the blank:


a. The result of the expression, (0.5 + 3/2) – 1/2 * 2, is 1.5
b. Ok4 can be a variable name. This statement is said to be _____True_____(True/False)
c. (11110111)8 is ( 249049 )16 and (56741)8= ( 101110111100001 )2 = ( 5de1 )16
d. The_a++__ and _a+=1__Is equivalent to a = a+1.
e. Consider the following statement: a=++y: where y=4, then the value of a is___5______.
f. In C, upper and lower cases letter are same. This expression is __False__(True.False)
g. An immediate exit from the loop can be achieved by a___break___ statement
h. ___%c__ code can be used to read/print a character
i. ____variable__ is a location in memory where a value can be stored for use by a
program.
j. Whenever a new value is placed in a memory location, that value overrides the previous
value in that location. This process is said to be ___True____(True/False).
k. Determine the values of variables product and x after the following calculation is
performed. Assume that product and x each have the value 3 when the statement begins
executing.
product *= x++; Product =_____9_____ and x = ______4________.
2. (20 Pts) Assume that the following codes work properly. What are the outputs of the
following programs?
a. Show your processing steps at the end of every loop iteration(5 Pts).
int x = 1, y = 7, z = 0;
while(++x <= y)
{
z+= x++;
printf("%d ", z);
}
printf("%d ", x);

Answer:
2 6 12 8
b. Show the output and explain your answer. (3 pts)
int a, b=70;
if(b<=80) a=100;
else a=300;
if(b<=100) a=200;
if(b<=120) a=400;
else a = 1000;
printf("%d ", a);
Answer:
400
c. Show the output and explain your answer (5 pts)
int main ()
{
int a=4, b;
b = 4;
b = a++;
printf ("%d %d %d %d", a++, --b, ++a, b--);
}

Answer:
5373

d. Show your processing steps at the end of every loop iteration and show the final
output. (7 pts)
x=10;
y=35;
a=x;
b=y;
while (b != 0)
{
t=b;
b=a%b;
a=t;}
h=a;
l=(x*y)/h;
printf("H= %d\n",h);
printf("L = %d",l);
}

Answer:
H= 5
L = 70

3. (9 pts) (Multiple Choices) Answer the following questions by selecting the correct choice.

a. Which is valid C expression?


A) int my_num = 100,000; B) int my_num = 100000; C) int my num = 1000; D) int $my_num =
10000;
b. What will be the output of the following C code?

#include <stdio.h>
void main(){int x = 5 % 2; printf("Value of x is %d", x);}
A) Value of x is 2.3 B) Value of x is 1 C)Value of x is 0.3 D)Compile time
error

c. What will be the output of the following C code?

#include <stdio.h>
int main()
{int i = 1,j=2;
if (i && j )printf("Yes\n");
else printf("No\n");}
A) Yes B) No C) Yes \n D) Compile time error

4. (15 pts) Find the error in each of the following code segments and explain how to correct it.
(Note: There may be more than one error.)
a. x = 1; => Missing data type
while (x <= 10 ); => without ;
x++;
}
b. switch ( n ) {
case 1:
printf( "The number is 1\n" ); => break
case 2:
printf( "The number is 2\n" );
break;
default:
printf( "The number is not 1 or 2\n" );
break;
}

c. int main ( void )


{ int x = 1 total = 0, y;
while ( x <= 10 ) {
y = x * x;
printf( "%d\n", &y ); => &
total += y--;
++x+; => ++x
}

5. (25 pts) (Flow - Charts) Flowchart is a diagrammatic representation of an algorithm. Draw


the flowcharts for the following problems.
a. (10 pts) A number is WOW if the sum of square of its digits is an even number that is
divisible by 4.
For example:
� 245, 2^2 + 4^2 + 5^2 = 45 => 45 is not an even number so 245 is not a WOW number.
� 123, 1^2+2^2+3^2 = 14 => 14 is an even number but not divisible by 4 so 123 is not a
WOW number.
� 444, 4^2 + 4^2 + 4^2 =48 => is an even number and divisible by 4 (48/4 = 12) so 444 is a
WOW number.

b. (15 pts)

6. (20 pts) (Programming) In this problem, you have to create a program in C that will ask
from a mobile operator client to enter total number of telephone calls. After getting the
total number of phone calls consumed in a month, the program will calculate and print the
bill (for that month) as per given call rate:
a. First 150 phone calls are free of charge.
b. Next 250 calls are charged at a rate of 0.5 $ per minute.
c. And rest calls (after 400 calls) are charged at the rate of 3.5 $ per minute.
Input Specification: You have to read one integer value for phone calls.
Output Specification: Calculate the bill.

Sample Input 1 Sample Output 1


140 You have not crossed the limit of 150 calls.
No charge

Sample Input 2 Sample Output 2

223 The bill you have to paid = 36.50 $

You might also like