18_spring_soln
18_spring_soln
Question 1: [2.5+2.5+2=7]
1 1 0 1 1 0 1 1
¬ 0 0 1 0 0 1 0 0
+ 1
0 0 1 0 0 1 0 1
Convert the magnitude to decimal: 001001012 = 2516 = 2×16 + 5 = 3710.
Since the original number was negative, the final result is 37.
(b) Show how a computer would perform 10 + 3 using eight bit two’s
complement representation. Is there a carry? Is there an overflow?
Answer:
10 + 3 = 7:
1 1 1 1 1
0 0 0 0 1 0 1 0
+ 1 1 1 1 1 1 0 1
0 0 0 0 0 1 1 1
Carryout without overflow. Sum is correct.
(c) Convert the 8bit signed two’s complement hex number 0x3F to
decimal.
Question 2: [4+4=8]
(a) Convert 35.75 to IEEE 754 floating point format. What is the hex
representation of the resultant bit pattern?
Answer: First, convert the hex to binary: 0100 0000 0010 0000 0000
0000 0000 0000
Then pull out each of the 3 pieces:
S: 0 (positive)
E: 1000 0000 = 128. Taking 128 127 = 1
M: 010 0000 0000 0000 0000 0000 So we have 1.01 * 21 = 10.1
Then convert that to decimal to get the answer: 2.5
Question 3:
int main()
printf("%d\n", a+b);
return 0;
Answer: 10 19 30
(b) #include<stdio.h>
p = 4;
*q = 2;
return (q);
int main()
int x = 6, y = 9, z = 3;
z = *fun(x, &y);
printf("%d %d %d\n", x, y, z);
return 0;
Answer: 6 2 2
(c) #include<stdio.h>
int main()
return 0;
Question 4:
#include<stdio.h>
*p = *p + *q;
*q = *p *q ;
*p = *p *q ;
int main()
// defining an array
int i=0;
int f = sizeof(a)/sizeof(int) 1;
int sum = 0;
return 0;
Question 5:
#include <stdio.h>
int main ()
{
double l, r, h, x, s;
s = 0;
return 0;
Question 6:
Complete the following program. Each blank can have at most one
statement. [1 + 2 + 1 = 4]
#include <stdio.h>
int main ()
int r, nroot = 0;
if (16 % r == 0) {
if (r*r*r4r*r4*r+16==0) {
nroot++ ;
nroot++ ;
return 0;
Question 7:
rand()%(n+1)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
i = 1;
while (1) {
a = rand()%100 – 8 ;
if ( a < 0 ) {
printf("...exiting...\n\n\n");
break;
}
if (i == 1) max = min = a ;
else {
++i;
return 0;
Question 8:
(a) #include<stdio.h>
int main()
while (1) {
x++;
if (y > z) break;
y += 4*x; z += 2*x;
return 0;
Answer: x = 4, y = 34, z = 32
(b) #include<stdio.h>
int main()
int s = 0;
return 0;
Answer: 4 5 6 7 8 9 10
Question 9:
What will be the output of the following C programs? Only one of the 4
choices are correct. Circle only the correct choice. [5x2 = 10]
n++;
*a = *a + n;
return *a;
int main()
int n=10;
n = fun(&n,++n);
printf("%d",n);
return 0;
A. 20 B. 21 C. 22 D. 23
int main ()
int i;
A[i] *= A[i1];
int main ()
h(A,4);
printf("%d", A[4]/A[3]);
return 0;
A. 16 B. 48 C. 2 D. 4
int f(int i)
return i%2;
int main()
int i=27;
while(f(i))
printf("%d", i);
i = i/2;
}
return 0;
A. 27 B. 27 13 C. 2713 D. 1
int i;
for(i=0;i<size;i++)
int main()
jumble(A, 10);
printf("%s", A);
return 0;
Question 10:
/**
*/
#include <stdio.h>
/* Function declarations */
int main()
scanf("%d", &start);
scanf("%d", &end);
printPerfect(start, end);
return 0;
/**
*/
int i, sum;
sum = 0;
if( num%i == 0 )
{
sum = sum + i ;
return 1;
else
return 0;
/**
* Print all perfect numbers between given range start and end.
*/
if( isPerfect(start) )
start++ ;