Midterm Questions - Answer Sheet
Midterm Questions - Answer Sheet
Midterm Questions - Answer Sheet
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.
#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
#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;
}
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.