Professional Documents
Culture Documents
Cp-Btech-08-Mid-Sem-19-09-08 With Answers
Cp-Btech-08-Mid-Sem-19-09-08 With Answers
Instructions:
1. Do Not Repeat Questions.
2. Answer New Question on New Page.
3. Q.1 to Q.8 are compulsory.
4. Q.9 is bonus question of 5 marks.
Q.1. State whether the following statements are true or false. [5]
A) Array occupies contiguous memory locations. [T]
B) In c/c++, all arrays have 0 as the index of their first element. [T]
C) Keywords can be used as variable names. [F]
D) ASCII-7 uses leftmost 7 bits of a byte. [F] RIGHT-MOST 7 BITS
E) BCD is unable to store 26 lower case alphabets. [T]
F) You can’t add an integer number to a pointer. [F]
G) char name[] = “PDPU-IPTG” occupies 9 bytes in the memory. [F] 10 BYTES
H) strlen() returns length of a string. [T]
I) strcmp() returns 0 if both strings are equal. [T]
J) while(1); is an infinite loop statement. [T]
B) (AB.CD)16 = ( ?) 8
Step 1 : Conversion from Hexa Decimal to Binary
Grouping into 4 Bits & comparing with 8421, we get
A = 1010 B = 1011 C = 1100 D = 1101
( 10101011.11001101)2
Step 2 : Conversion from Binary to Octal
Grouping into 3 bits & comparing with 421, we get
( 010 101 011.110 011 010 )2
( 2 5 3 . 6 3 2 )8
Page 1 of 8
PANDIT DEENDAYAL PETROLEUM UNIVERSITY
INSTITUTE OF PETROLEUM TECHNOLOGY, GANDHINAGAR
B.TECH 2008-MID-SEMESTER EXAM COMPUTER PROGRAMMING (ESC101)
Roll No. _____ Batch No. ____
C) (705.25)8 = ( ? ) 2
= 7 0 5 . 2 5
Comparing with 421, we get
= (111 000 101 . 010 101) 2
-28 27 26 25 24 23 22 21 20
-256 128 64 32 16 8 4 2 1
1 1 0 0 1 0 1 1 1
The first binary digit is dropped. Fraction part on the right is filled with 0s on right-hand side
upto 23 bits, we get: 01000001000000000000000
The exponent is 4. Adding 127 bias in it, we get 131. Converting 131 in binary,
we get: 10000011
Q. 4. Write the output for the following segment of the program. [5]
a) int i = 4 , j = 5; b) int a = 10, * b = &a, **c = &b;
if (++i > j - -) **c = *b + 10; c++;
cout << i << “ “ << j ; cout << *c;
cout << i << “ “ << j ; (if addresses of a ,b and c are 65524,
65522 & 65520 respectively.)
(Assume 16-bit compiler)
5 4 20
Explanation: Explanation:
In if condition, ++i will make value of i to 5. Here, b & c are integer pointers.
This value will be checked with value of b is pointing to a, while c contains
j, which is 5. The condition result is false. address of b i.e. 65522. When we
Thereafter, value of j is reduced by 1. execute c++, the value of c gets
Hence, the above output. changed to 65524. This is the address
of a. So *c will give value 20 as output.
Remember, **c and *b are pointing to
Variable a only. So value of a gets
changed to 20 by statement **c=*b+10;
Page 2 of 8
PANDIT DEENDAYAL PETROLEUM UNIVERSITY
INSTITUTE OF PETROLEUM TECHNOLOGY, GANDHINAGAR
B.TECH 2008-MID-SEMESTER EXAM COMPUTER PROGRAMMING (ESC101)
Roll No. _____ Batch No. ____
Fail
Explanation: As p contains 30, 1st block of conditions becomes true.
1 10
10 100
100 1000
1000
10000
Q.5. Find out 10 errors in the following segment of the program & rewrite it. [5]
main( ) Dbl(int x, int y);
{ {
int a = 10; b = 20; int x;
dbl(&a, &b); x = x + x;
cout >> a >> “ “ >> b; y = y + y;
} }
Answer:
void main( ) void dbl(int * x, int * y) remove ;
{ {
int a = 10, b = 20; int x;
void dbl(int *, int *); *x = *x + *x;
dbl(&a, &b); *y = *y + *y;
cout << a << “ “ << b; }
}
Page 3 of 8
PANDIT DEENDAYAL PETROLEUM UNIVERSITY
INSTITUTE OF PETROLEUM TECHNOLOGY, GANDHINAGAR
B.TECH 2008-MID-SEMESTER EXAM COMPUTER PROGRAMMING (ESC101)
Roll No. _____ Batch No. ____
INPUT N
T=N
y
IF N = 1 PRINT 0, “!”®
n|
V
I=0
© I = I + 1
N=N/I
y
IF N > 1 ©
n|
V y
IF N = 1 PRINT I, “ IS FACTORIAL OF “ , T ®
n|
V
PRINT “FACTORIAL OF “ , T , “ NOT FOUND “
® STOP
Or
Q.6. Draw flowchart to calculate the value of a raised to b. (ab) [10]
Where b should be a positive integer only. Reenter the value of b, if it is not
positive.
Page 4 of 8
PANDIT DEENDAYAL PETROLEUM UNIVERSITY
INSTITUTE OF PETROLEUM TECHNOLOGY, GANDHINAGAR
B.TECH 2008-MID-SEMESTER EXAM COMPUTER PROGRAMMING (ESC101)
Roll No. _____ Batch No. ____
START
INPUT A
INPUT B
y
IF
B <= 0
ANS = 1
I=0
I=I+1
ANS = ANS * A
y
IF
I<B
n
PRINT ANS
STOP
Page 5 of 8
PANDIT DEENDAYAL PETROLEUM UNIVERSITY
INSTITUTE OF PETROLEUM TECHNOLOGY, GANDHINAGAR
B.TECH 2008-MID-SEMESTER EXAM COMPUTER PROGRAMMING (ESC101)
Roll No. _____ Batch No. ____
Q.7. Write C/C++ program for the following. [10]
A) Summation of digits of a given no. e.g. 351 = 3+5+1 = 9
#include <iostream.h>
#include <conio.h>
void main()
{
int n;
int sumofdigit(int); // function prototype
cout << “Enter a Number” << endl;
cin >> n;
cout << sumofdigit(n);
getch();
}
int sumofdigit(int n)
{
int q,r,s = 0;
do
{
q = n / 10;
r = n % 10;
s += r;
n = q;
} while ( n );
return s;
}
#include <iostream.h>
#include <conio.h>
void main()
{
int i,v,h,l;
cout << “Enter a Number “ << endl;
cin >> v;
// assuming the 1st no. entered is highest as well as lowest.
h = v;
l = v;
for(i=2;i<=100;i++)
{
cout << “Enter a Number “ << endl;
cin >> v;
if (v>h)
Page 6 of 8
PANDIT DEENDAYAL PETROLEUM UNIVERSITY
INSTITUTE OF PETROLEUM TECHNOLOGY, GANDHINAGAR
B.TECH 2008-MID-SEMESTER EXAM COMPUTER PROGRAMMING (ESC101)
Roll No. _____ Batch No. ____
v = h;
else
if ( v < l )
l = v;
}
cout << “Highest Value = “ << h << endl;
cout << “Lowest Value = “ << l << endl;
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
int a[10],i,j,n;
clrscr();
// Accept 10 values & no. to be deleted from the user.
cout << "Enter 10 values" << endl;
for(i=0;i<10;i++)
{
cin >> a[i];
}
cout << "Enter the Number to be removed from the array " ;
cin >> n;
Page 7 of 8
PANDIT DEENDAYAL PETROLEUM UNIVERSITY
INSTITUTE OF PETROLEUM TECHNOLOGY, GANDHINAGAR
B.TECH 2008-MID-SEMESTER EXAM COMPUTER PROGRAMMING (ESC101)
Roll No. _____ Batch No. ____
}
a[9] = 0; // at the end of the list, put zero.
}
}
Page 8 of 8